VBA & Macro Problems

Insert a Permanent Timestamp When an Excel Cell Changes

Emma BrownEmma Brown Dec 2, 2026 868 views

Question details

Record a fixed date and time in one cell when a neighboring Excel cell is entered or updated.

Insert a Permanent Timestamp When an Excel Cell Changes
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet tracks unit sign-in and sign-out times alongside entered data.
Observed behavior
The user wants a timestamp in C6 when B6 is entered or updated, without the timestamp changing during later recalculations.
Before you start

Open the workbook in desktop Excel and identify the worksheet containing B6 and C6. Confirm that C6 is available for the timestamp and that you can enable macros from a trusted source.

Solution 1Recommended

Use a Worksheet Change Event to Timestamp B6

Use VBA to write a fixed timestamp to C6 whenever B6 is entered or updated.

The timestamp updates each time B6 is edited and is cleared if B6 is cleared. Unlike a NOW() formula, the stored value does not change when the workbook recalculates.

1
Open the worksheet code

In desktop Excel, right-click the relevant worksheet tab and select View Code.

2
Add the event macro

Paste this code into the worksheet's code window: Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Me.Range("B6")) Is Nothing Then Exit Sub On Error GoTo CleanUp Application.EnableEvents = False If Len(Me.Range("B6").Value2) > 0 Then Me.Range("C6").Value = Now Me.Range("C6").NumberFormat = "yyyy-mm-dd hh:mm:ss" Else Me.Range("C6").ClearContents End If CleanUp: Application.EnableEvents = True End Sub

3
Save as a macro-enabled workbook

Return to Excel, select File > Save As, and choose Excel Macro-Enabled Workbook (*.xlsm).

4
Enable and test the macro

If prompted when opening the trusted workbook, select Enable Content. Enter or edit a value in B6 and check that C6 shows the current date and time.

Use a Worksheet Change Event to Timestamp B6
Formula changes do not trigger this event: Worksheet_Change responds to edits to B6, including pasted values, but not to changes caused only by formula recalculation.
Free Microsoft Office alternative

Manage Time-Tracking Workbooks in WPS Spreadsheet

WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface. Open compatible Excel workbooks and move everyday time-tracking tasks to WPS easily; check macro compatibility before relying on an Excel VBA event.

Organize sign-in and sign-out records in a familiar spreadsheet interfaceOpen and edit compatible Microsoft Excel XLSX and XLS filesUse a free, lightweight Office suite for everyday workbook tasksMove standard spreadsheet data into WPS without rebuilding it
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't =IF(B6<>"",NOW(),"") preserve the entry time?

NOW() is volatile, so its result can update when Excel recalculates. A worksheet change macro writes the current time as a fixed value instead.

Will the timestamp change if I edit B6 again?

Yes. The provided macro writes a new timestamp to C6 each time B6 is edited. Clearing B6 also clears C6.

Why isn't the timestamp appearing?

Make sure the code is in the correct worksheet's code window, the workbook is saved as an XLSM file, and macros are enabled for the trusted workbook. Also check that B6 was edited directly rather than changed only by a formula recalculation.

Can I record sign-in and sign-out in separate cells?

Yes. Use separate input and timestamp cells for each event, and adapt the worksheet change code to check each input cell and write to its corresponding timestamp cell.