VBA Range / Cell Address
In this Article
Get Range Address
This will display the cell address using the Range object:
1 |
MsgBox Range("A1").Address |
Get Cells Address
This will display the cell address using the Cells object:
1 |
MsgBox Cells(1,1).Address |
ActiveCell Address
To get the ActiveCell address use this code:
1 |
MsgBox ActiveCell.Address |
Set Variable to Cell Address
You can also assign the cell address to a string variable:
1 2 3 4 5 |
Dim strAddress strAddress = Range("A1").Address MsgBox strAddress |
Get Row Number From Cell Address
This code will extract the row number from an address:
1 2 3 4 5 6 7 8 9 10 11 |
Sub GetRowNumberFromCellAddress() Dim strAddress As String Dim rownum As Long strAddress = Range("A1:a10").Address rownum = Range(strAddress).Row MsgBox rownum End Sub |
However, usually you can use this much simpler code:
1 |
MsgBox Range("A1").Row |