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

3 answers

Sort by: Most helpful
  1. Brian Pham (WICLOUD CORPORATION) 1,090 Reputation points Microsoft External Staff Moderator
    2026-11-02T03:26:30.6866667+00:00

    Hi @Albert Kremer ,

    If you need to determine the position of the currently selected cell in Excel VBA, the ActiveCell object provides access to both its coordinates and worksheet reference.

    Dim rowNumber As Long
    Dim columnNumber As Long
     
    rowNumber = ActiveCell.Row
    columnNumber = ActiveCell.Column
    

    You can also retrieve the cell address if you need a worksheet reference in addition to the numeric row and column values:

    MsgBox "Cell Address: " & ActiveCell.Address & vbCrLf & _
           "Row: " & ActiveCell.Row & vbCrLf & _
           "Column: " & ActiveCell.Column
    

    For example, when cell D7 is selected:

    • ActiveCell.Address returns $D$7
    • ActiveCell.Row returns 7
    • ActiveCell.Column returns 4

    The Address property can be useful when logging, reporting, or displaying the currently selected cell, as it provides the familiar worksheet reference rather than only numeric coordinates.

    I hope this helps.

    If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation.

    Thank you.

    Was this answer helpful?

    0 comments No comments

  2. Marcin Policht 112.2K 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

  3. 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.