How To Get Active Cell Address In Excel Vba

How to Get Active Cell Address in Excel VBA

To get the address of the active cell in Excel VBA, you can use the ActiveCell.Address property. This property returns a string value representing the address of the active cell.

Here’s an example:


Sub GetActiveCellAddress()
    Dim activeCell As Range
    Set activeCell = ActiveCell
    MsgBox "The active cell address is: " & activeCell.Address
End Sub
  

In this example, we first declare a variable activeCell of type Range. We then use the ActiveCell property to assign the active cell to the activeCell variable. Finally, we use the MsgBox function to display a message box showing the active cell address.

When you run this macro, it will display a message box with the active cell address similar to $A$1 or B2, depending on the active cell in your worksheet.

Similar post

Leave a comment