An implementation of Visual Basic that is built into Microsoft products.
Use ActiveCell.Row and ActiveCell.Column to obtain the active cell’s row and column numbers.
Sub ShowActiveCellPosition()
Dim rowNumber As Long
Dim columnNumber As Long
rowNumber = ActiveCell.Row
columnNumber = ActiveCell.Column
MsgBox "Row: " & rowNumber & vbCrLf & _
"Column: " & columnNumber
End Sub
ActiveCell returns the single active cell as a Range object, even when multiple cells are selected.^1^ Its Row and Column properties return read-only Long values.^2^^3^
For example, if D7 is active:
-
ActiveCell.Rowreturns7 -
ActiveCell.Columnreturns4because column A is 1, B is 2, and so on.
The active window must display a worksheet; otherwise, ActiveCell fails.^1^
References