Displaying The Selected Cell's Address - Microsoft Excel Tips
Maybe your like
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 FunctionThe 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:
=CurrentCellYou 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:
- Display the VBA Editor by pressing Alt+F11.
- 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.)
- 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.
- Change the event handler so it appears as follows: Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) Range("A1").Value = ActiveCell.Address End Sub
- Close the VBA Editor.
Now, as you move about this single sheet, the contents of A1 should be constantly updated to reflect your location.
Tag » Active Cell Address In Excel Vba
-
VBA Active Cell - WallStreetMojo
-
How To Use ActiveCell In VBA In Excel
-
How To Get The Address Of Active Cell In Excel? - ExtendOffice
-
Working With The Active Cell | Microsoft Docs
-
Return Address Of Active Cell Using Excel And VBA - Exceldome
-
Get The Active Cell's Column Or Row - VBA Code Examples
-
VBA Range / Cell Address - Automate Excel
-
Different Examples Of Excel VBA Active Cell - EduCBA
-
How To Get The Active Cell Address In Excel
-
Active Cell Address In Excel Through Visual Basic - YouTube
-
Using VBA To Add Active Cell Address To A Range - Stack Overflow
-
Extract Current Cell Address - Excel - Stack Overflow
-
Using VBA Cell Address In Formula | MrExcel Message Board
-
Need Help With VBA To Copy Active Cell Address To Range Variable