Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Displaying the Selected Cell's Address.

Displaying the Selected Cell's Address

by Allen Wyatt
(last updated March 16, 2016)

10

Excel allows you to easily see the location of the currently selected cell by examining the contents of the Name Box, to the left of the Formula Bar. This is fine and good, but there are times when you would like to have the address of a cell actually in a cell. For instance, you may want cell A1 to contain the address of the currently selected cell. This means that if cell E4 were selected, then A1 would contain its address, or $E$4. If you then pressed the right-arrow key, then the contents of A1 would change to $F$4.

In order to return the address of the currently selected cell, you must resort to using macros. The following macro will return the value of the cell selected at the time it is run:

Public Function CurrentCell() As String
    Application.Volatile
    CurrentCell = ActiveCell.Address
End Function

The inclusion of the Application.Volatile method means that every time the worksheet is recalculated, this function (macro) is again run. To use the macro you can place the following in any cell desired, including A1:

=CurrentCell

You should note that this macro doesn't result in the contents of A1 changing every time you move to a different cell. Again, the contents of A1 will change only when the workbook is recalculated, either by changing something in the worksheet or by pressing F9.

If, instead, you need to have a "real time" version that automatically updates A1 as the selected cell is changed, you can follow these steps:

  1. Display the VBA Editor by pressing Alt+F11.
  2. In the Project window, at the left side of the Editor, double-click on the name of the worksheet you are using. (You may need to first open the VBAProject folder, and then open the Microsoft Excel Objects folder under it.)
  3. In the code window for the worksheet, click on the Object drop-down list and choose Worksheet. When you do, the Procedure should change to SelectionChange, and the framework for the event handler should appear in the code window.
  4. Change the event handler so it appears as follows:
  5. Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
        Range("A1").Value = ActiveCell.Address
    End Sub
    
  6. Close the VBA Editor.

Now, as you move about this single sheet, the contents of A1 should be constantly updated to reflect your location.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2302) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Displaying the Selected Cell's Address.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Determining if Num Lock is On

Need to know if the Num Lock key is on or off? You can use a short bit of macro code to figure out the state of the key.

Discover More

Locking Icons on the Desktop

Your desktop is supposed to be place where you can put your most-often-used program and file icons. You can spend hours ...

Discover More

Jumping to the End of Page after Enter

Imagine you start typing in a new document, and when you press the Enter key the cursor jumps a huge distance to the ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (menu)

Deleting Worksheets in a Macro

Processing workbooks using a macro often involves the possible creation and subsequent deletion of worksheets. When it ...

Discover More

Positioning a Column on the Screen

If you have static columns and dynamic columns on the screen, you may want the dynamic columns to always show a ...

Discover More

Reorganizing Data

If you need to consolidate a single column of data into multiple columns of data, you'll love this macro. It provides a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five minus 4?

2018-05-02 13:10:50

Ryan

Hello Allen,
Thank you very much for this wonderful guidance. I find it very useful.
Would you please kindly advise on how the “real time” code can me modified such that when two sheets (within the same file) are open side by side, Sheet2 A1 will display the address of the active/selected cell in Sheet1?
As I intend to subsequently run a vlookup based on that result, it would be great if the result can also include the name of the sheet.
Thank you very much!


2017-05-31 14:59:29

Willy Vanhaelen

@All
BTW: =CurentCell yields an error.
The correct syntax is: =CurrentCell()


2017-05-31 14:53:04

Willy Vanhaelen

@abh
If you select a range of cells, the active cell can be anywhere in the range by hitting tab or Ctrl + . (period). If that's what you mean the first UDF will give you the result after a recalc (F9 or shift+F9).


2017-05-30 05:02:03

Michael (Micky) Avidan

@abh,
I am also not sure I got to the bottom of your question but i'll give it a try.
If you meant to get the Range address of the selected cells (more than one cell)
then try:
---------------------------------------------
Function CurrentRangeAddress()
Application.Volatile
CurrentRangeAddress = Selection.Address
End Function
-------------------
Pls Note: changing the selected range will not recalculate the Function - therefore you'll have to press [F9] to re-evaluate the ranges address.
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” Excel MVP – Excel (2009-2017)
ISRAEL


2017-05-30 02:55:09

Alan Elston

Hi abh
I do not fully understand your question.

But a few points:
I think as you make a selection manually , the first cell you select becomes the active cell. So the active cell will become the corner you selected before dragging across to complete the selection
If you select a range with a code, then the active cell becomes the Top Left cell of the first area ( or only area if only one is ) selected.

So what ever was the active cell before the selection is made is no longer the active cell.

So you would need to determine the current active cell before a selection was made.

Alan


2017-05-29 13:23:16

abh

do you know if it is possible to get the active cell of a selected cells range??


2016-10-20 12:56:57

mrs. Satrouis21

thank you so much this program is amazing and cool i like it so much.


2016-10-20 12:55:55

f

Thank you so much its great!!!!!!!!!!!!!!!!!


2015-03-12 22:12:43

WonJe Jo

Thank you so much!! it's great!!! Your teaching is also excellent!!! Thank you.


2012-12-30 06:14:52

Pieter de la Court

The function Cell("Address") does exactly the same as the macro above.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.