2016-06-23 11 views
0

"E15"や "A3"のように、最初の空のセルの名前が必要です worksheet.Cells.Nameとworksheet.Rows.Nameを使用しようとしましたが、そうではありません 正しい構文...助けてください!vb.netでExcelのセル名を取得するにはどうすればよいですか?

は、ここに私のコードです

Dim xlApp As Excel.Application 
    Dim xlWorkBook As Excel.Workbook 
    Dim xlWorkSheet As Excel.Worksheet 
    Dim misValue As Object = System.Reflection.Missing.Value 

    xlApp = New Excel.Application 
    xlWorkBook = xlApp.Workbooks.Add(eXe) 
    xlWorkSheet = xlWorkBook.Sheets("sheet1") 



    Dim eColumn As Excel.Range = xlWorkSheet.Range("E2:E15") 
    Dim rCell As Excel.Range 




    For Each rCell In eColumn 
     If rCell Is Nothing Then 
      Dim LastCell As String = xlWorkSheet.Rows.Name 
      MsgBox(LastCell) 
     End If 
     MsgBox(rCell.Value) 
    Next rCell 

(更新)

は、私は、次のコードを使用し、$ Eに$ 15だ、「$」記号アウトでアドレスを取得する方法はありますか?

For Each rCell In eColumn 
     If rCell.Value = "" Then 
      Dim LastCell As String = rCell.Cells.Address 
      MsgBox(LastCell) 
     End If 
     MsgBox(rCell.Value) 
    Next rCell 
+1

から取られている必要はありません任意の$兆候を省略しなければならない

dim CellName as String = columnLetter & rownum ' the row number you need 

を使用すると、 '.Address'何です探している? – BruceWayne

+0

vb.netまたはvbaを使用していますか?私の帽子の上からそれを試していないから:これまでずっと繰り返していたセルなので、if(cell.value = "")、次にcell.address – surfmuggle

+0

google luke:[relative-cell-address-needed- excel-vba](http://stackoverflow.com/questions/24933692/) また、[find-and-select-first-blank-cell-in-column-b-excel-vba](http: //stackoverflow.com/questions/25155751/)または[select-first-empty-cell-in-column-f-starting-from-one-using-off-offset](http://stackoverflow.com/質問/ 14957994 /) – surfmuggle

答えて

1

coloumn利用の名前を取得するには:あなたはすでにあなたが探している行番号を取得する方法を知っている

Dim columnLetter As String = ColumnIndexToColumnLetter(85) ' returns CG 
Private Function ColumnIndexToColumnLetter(colIndex As Integer) As String 
    Dim div As Integer = colIndex 
    Dim colLetter As String = String.Empty 
    Dim modnum As Integer = 0 

    While div > 0 
     modnum = (div - 1) Mod 26 
     colLetter = Chr(65 + modnum) & colLetter 
     div = CInt((div - modnum) \ 26) 
    End While 

    Return colLetter 
End Function 

事を。それからちょうどこれは、あなたが

例はhere

よろしく、 Iakov

関連する問題