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: Identifying the Last Cell Changed in a Worksheet.

Identifying the Last Cell Changed in a Worksheet

Written by Allen Wyatt (last updated April 13, 2022)
This tip applies to Excel 97, 2000, 2002, and 2003


1

John wonders if there is a way in VBA to identify the last cell that was changed by a user. He doesn't want to know if the cell was changed by a macro, but specifically by a user.

The answer is yes—sort of. You can use the Worksheet_Change event to write a handler that will record when any particular cell in a worksheet is changed. A macro that does this could be rather simple, such as this one:

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.StatusBar = Target.Address
End Sub

The macro simply puts the address of the last change into the status bar. You could modify the macro so that it maintained the address in a global variable (declared outside of the event handler) in this manner:

Dim sAddr As String

Private Sub Worksheet_Change(ByVal Target As Range)
    sAddr = Target.Address(False, False)
End Sub

You then could use a regular macro to retrieve the address stored in the sAddr variable and do whatever you want with it.

As for making sure that the event handler doesn't record any changes done by macros, the only way to do this is to turn off event handling before executing any macro command that will modify the worksheet. For instance, the following EnableEvents property change could be used before and after a command that changes the contents of cell A1:

Application.EnableEvents = False
Range("A1") = "Hello"
Application.EnableEvents = True

With event handling turned off, the Worksheet_Change event handler won't be triggered and the "last changed" address won't be updated. The result is that you end up tracking only those changes done by users, not changes done by macros.

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 (3819) 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: Identifying the Last Cell Changed in a Worksheet.

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

Converting PDF to Word Documents

One way that documents are commonly shared with others is in the form of a PDF file. Getting information from a PDF file ...

Discover More

Determining the Month of the Year

Your macro code may need to determine the month of the year represented by a particular date. You can find the desired ...

Discover More

Changing Built-in Word Commands

Want to replace Word's internal commands with your own macros? It's easy to do if you know the key discussed in this tip.

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (menu)

Hiding and Unhiding Worksheets

Worksheets are easily accessible in a workbook, but you may not want them to be so open. You can hide worksheets so they ...

Discover More

Viewing Two Worksheets At Once

If you need to work on two worksheets in the same workbook at the same time, Excel makes this rather easy to do. All you ...

Discover More

Referencing a Worksheet Name

Excel provides ways to reference the column or row number of a cell, but it doesn't provide a built-in way to reference 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}] (all 7 characters, in the sequence shown) 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 8 - 5?

2018-01-01 08:07:34

Varun

Hello,

Is there a way in VBA to identify the last cell value that was changed by a formula.

For example, column 'A' has a formula in it which takes its values from cells in columns adjacent to it( Columns B, C, D, E, F and G respectively). These columns may contain either default values or values which the user enters or changes. I need to find out the cell address in Column A whose value changes.

Thanks!


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.