How to Automatically Add a Date and Time Stamp Using Excel VBA
Question details
The user wants to automatically populate a date and time in column C whenever a value is entered or changed in column B using a worksheet event macro.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Tracking data entry times by auto-generating a timestamp in an adjacent cell.
- Observed behavior
- Requires a reliable macro that inserts timestamps accurately based on cell modifications without causing recursion errors.
Ensure that the Developer tab is enabled in your spreadsheet program and remember to save your file as a Macro-Enabled Workbook (.xlsm) to preserve the VBA code.
Create a Worksheet_Change Event Macro
Use a custom VBA script triggered by the Worksheet_Change event to automatically insert a timestamp when a specific column is edited.
This solution utilizes the Worksheet_Change event to monitor column B. When a change is detected, it instantly inserts the current date and time into column C of the same row.
To prevent the macro from triggering itself and causing an infinite loop, Application.EnableEvents is temporarily disabled during the timestamp insertion.
Press Alt + F11 on your keyboard to launch the Visual Basic for Applications (VBA) editor.
In the Project Explorer pane on the left, double-click the specific sheet where you want the timestamp to appear (for example, Sheet1).
Paste your Worksheet_Change code into the window. Ensure your logic checks if Target.Column equals 2 (Column B), disables Application.EnableEvents, sets Target.Offset(0, 1).Value to Now, and then re-enables Application.EnableEvents.
Close the VBA editor and return to your spreadsheet. Type any value into column B; column C will immediately populate with the current date and time.

Automate Your Workflows Using VBA in WPS Spreadsheet
WPS Office provides robust support for VBA and Macros, allowing you to easily automate tasks like date and time stamping. Its spreadsheet environment closely mirrors Excel, making it simple to write, run, and manage your VBA scripts seamlessly.
- 1. Enable Developer Tools: Open WPS Spreadsheet, navigate to the Developer tab, and click to ensure Macros are enabled.
- 2. Launch the VBA Editor: Click the 'Visual Basic' button on the ribbon or press Alt + F11 to open the code editor.
- 3. Write Your Event Code: Double-click your active worksheet in the Project window and input your Worksheet_Change timestamp code.
- 4. Save as Macro-Enabled: Go to File > Save As, and choose the Macro-Enabled Workbook (.xlsm) format to keep your VBA scripts intact.

Frequently Asked Questions
How can I format the timestamp to show only the date or only the time?
You can change the visual display by right-clicking the target cells in column C, selecting 'Format Cells', and choosing your desired Date or Time format. Alternatively, you can modify the VBA code to use 'Date' or 'Time' instead of 'Now' to restrict the actual recorded value.
Why isn't my VBA macro triggering when I type in the cell?
Ensure that macros are fully enabled in your Trust Center or Developer settings. If an error occurred previously while testing, 'Application.EnableEvents' might have been left disabled. You can reset it to True by typing 'Application.EnableEvents = True' in the Immediate Window (Ctrl+G) within the VBA editor and pressing Enter.
How do I apply this timestamp macro to monitor multiple specific columns?
In your Worksheet_Change VBA code, you can modify the target condition to check for multiple column indices. For example, using an 'If Target.Column = 2 Or Target.Column = 4 Then' statement allows the macro to monitor both columns B and D for changes.




