VBA Range / Cell Address

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on October 1, 2021

This tutorial will demonstrate how to get a cell’s address.

Get Range Address

This will display the cell address using the Range object:

MsgBox Range("A1").Address

vba range cell address

Get Cells Address

This will display the cell address using the Cells object:

MsgBox Cells(1,1).Address

ActiveCell Address

To get the ActiveCell address use this code:

MsgBox ActiveCell.Address

Set Variable to Cell Address

You can also assign the cell address to a string variable for easy use within your code:

Dim strAddress As String
strAddress = Range("A1").Address

MsgBox strAddress

 

Get Row Number From Cell Address

This code will extract the row number from an address:

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:

MsgBox Range("A1").Row

 

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!
vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples