VBA & Macro Problems

How to Record the Last Worksheet Change Date and Time Using VBA

Elise WilliamsElise Williams Nov 11, 2026 869 views

Question details

The user needs to automatically record the exact date and time whenever a cell is modified on any worksheet, without having to write separate VBA event procedures for each individual sheet.

How to Record the Last Worksheet Change Date and Time Using VBA
Product
Spreadsheets
Device & OS
not provided
Scenario
Tracking modifications across a workbook with dozens of sheets to keep an accurate log of when each worksheet was last updated.
Observed behavior
Instead of duplicating code across 50 individual sheet modules, the user wants a centralized script that leverages the Workbook_SheetChange event, including exceptions for specific overview sheets.
Before you start

Ensure you save your spreadsheet as a Macro-Enabled Workbook (.xlsm) before adding the code, otherwise your VBA script will be permanently lost when you close the file.

Solution 1Recommended

Use the ThisWorkbook Module for Global Sheet Change Tracking

By placing a Workbook_SheetChange event in the ThisWorkbook module, you can track cell changes across all worksheets using a single block of VBA code.

Instead of maintaining separate Worksheet_Change codes for dozens of sheets, using the global Workbook_SheetChange event allows you to apply the timestamp rule to the entire file. You can easily use a Select Case statement to exclude specific summary or overview sheets from this automation.

1
Open the VBA Editor

Press the shortcut 'Alt + F11' on your keyboard to open the Visual Basic for Applications (VBA) editor window.

2
Access the ThisWorkbook Module

In the Project Explorer pane on the left side of the VBA editor, locate your current file and double-click on 'ThisWorkbook'.

3
Insert the Event Code

Paste the following script into the blank code window: Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) Select Case Sh.Name Case "Overview1", "Overview2" Case Else Application.EnableEvents = False Sh.Range("Z1").Value = Now Application.EnableEvents = True End Select End Sub.

4
Customize the Excluded Sheets and Timestamp Location

Modify the text 'Overview1', 'Overview2' in the code to match the exact names of the sheets you want to exclude. To change where the timestamp appears, change 'Z1' to your preferred cell reference.

5
Save and Test

Save your macro-enabled workbook. Go to any tracked worksheet and edit a cell. The current date and time will automatically appear in cell Z1 (or your specified cell).

Use the ThisWorkbook Module for Global Sheet Change Tracking
Why Application.EnableEvents is Crucial: The line 'Application.EnableEvents = False' is essential. It temporarily turns off event triggers so that the macro's action of writing the timestamp into cell Z1 doesn't trigger another change event, which would result in an infinite loop.
Efficient Macro Handling with WPS

Easily Manage VBA Macros in WPS Spreadsheet

WPS Office offers a fully integrated VBA environment, allowing you to seamlessly implement time-saving automations like the Workbook_SheetChange event to track worksheet updates.

  1. 1. Download and Install WPS Office: Get the latest version of WPS Office Free from the official website and open your macro-enabled spreadsheet.
  2. 2. Access the Developer Tools: Navigate to the 'Developer' tab on the top ribbon menu to access all macro and VBA functions.
  3. 3. Launch the VBA Editor: Click the 'Visual Basic' icon or press Alt+F11 to open the built-in VBA editor and implement your automated timestamp scripts.
Fully compatible with Microsoft Excel VBA macros and .xlsm formatsLightweight application that executes macro operations quicklyFamiliar Visual Basic developer interface with no learning curveIncludes a built-in macro error handler for easier debugging
microsoft office alternative - wps office

Frequently Asked Questions

Why is my VBA timestamp not updating when I change a cell?

Macros might be disabled in your workbook. Check your security settings under the Developer tab to ensure macros are enabled. Also, if a previous macro error occurred while Application.EnableEvents was set to False, you must manually reset it to True in the Immediate Window for the event to fire again.

Do I need to update this code every time I add a new worksheet?

No. Because the code is placed in the global ThisWorkbook module, it automatically tracks changes on any newly added worksheets unless you explicitly add their names to the exclusion list in the Select Case statement.

How can I record the specific cell address that was modified?

The 'Target' parameter in the Workbook_SheetChange event refers to the specific cell that was changed. You can record 'Target.Address' in an adjacent cell to log exactly which cell triggered the timestamp.

Can I record the username of the person who made the change?

Yes, you can modify the VBA script to record 'Application.UserName' alongside the 'Now' function so you can track both the time of the change and the user who made it.