Visual Basic syntax question

Albert Kremer 0 Reputation points
2026-10-31T19:23:32.5833333+00:00

Using Visual Basic programming language, how do I determine the row and column numbers of the active cell?

Developer technologies | Visual Basic for Applications
0 comments No comments

2 answers

Sort by: Most helpful
  1. Marcin Policht 112.1K Reputation points MVP Volunteer Moderator
    2026-10-31T21:45:39.1766667+00:00

    In Excel VBA, use the ActiveCell.Row and ActiveCell.Column properties to determine the row and column numbers of the currently selected cell.

    Sub GetActiveCellPosition()
    
        Dim RowNumber As Long
        Dim ColumnNumber As Long
    
        RowNumber = ActiveCell.Row
        ColumnNumber = ActiveCell.Column
    
        MsgBox "Row: " & RowNumber & vbCrLf & _
               "Column: " & ColumnNumber
    
    End Sub
    

    For example, if the active cell is D5, ActiveCell.Row returns 5 and ActiveCell.Column returns 4.

    You can also retrieve both values directly without declaring variables:

    Debug.Print ActiveCell.Row
    Debug.Print ActiveCell.Column
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-10-31T19:23:57.38+00:00

    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.Row returns 7
    • ActiveCell.Column returns 4 because column A is 1, B is 2, and so on.

    The active window must display a worksheet; otherwise, ActiveCell fails.^1^


    References

    1. Application.ActiveCell property (Excel)
    2. Range.Row property (Excel)
    3. Range.Column property (Excel)
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.