Insert Today’s Date in an Excel Cell on Double-Click
Question details
Insert a fixed current date into selected Excel cells when they are double-clicked.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user wants to date cells in specified columns and rows without updating the date automatically.
- Observed behavior
- Double-clicking an eligible cell should insert the date in that same cell and leave it unchanged until the cell is double-clicked again.
Open the workbook in a desktop version of Excel that supports VBA, and identify the worksheet where the date should be inserted. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros only if you trust the file.
Use a worksheet double-click event to insert the date
Use this VBA event to insert a fixed date in the clicked cell within AF23:AF375, AH23:AH375, AJ23:AJ375, or AL23:AL375.
The event cancels normal cell editing in the specified ranges and asks before replacing an existing value or formula. It writes a date value, not a formula, so the date does not change automatically.
Right-click the target worksheet tab and select View Code. Paste the code in that worksheet’s module, not in a standard module.
Paste this code into the worksheet module: Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim oldEvents As Boolean Dim errorMessage As String If Intersect(Target, Me.Range("AF23:AF375,AH23:AH375,AJ23:AJ375,AL23:AL375")) Is Nothing Then Exit Sub Cancel = True If Not IsEmpty(Target.Value) Then If MsgBox("Replace the existing value with today's date?", vbYesNo + vbQuestion) <> vbYes Then Exit Sub End If oldEvents = Application.EnableEvents On Error GoTo HandleError Application.EnableEvents = False Target.Value = Date Application.EnableEvents = oldEvents Exit Sub HandleError: errorMessage = Err.Description Application.EnableEvents = oldEvents MsgBox "The date could not be inserted: " & errorMessage, vbExclamation End Sub
Save the workbook as .xlsm, return to the worksheet, and double-click a cell in one of the specified ranges. If it already contains a value, select Yes to replace it; double-clicking outside the ranges retains normal behavior.
If the inserted value appears as a number, select the affected cells, open Format Cells, and choose a Date format.

Work with dated spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Excel files. It makes it easy to move everyday spreadsheet work from Microsoft Office, though it does not fix Excel’s VBA event behavior and macro support may vary.

Frequently Asked Questions
Why does the date stay the same tomorrow?
The VBA code writes the current date as a fixed cell value. Unlike the TODAY() formula, it does not recalculate each day.
How do I change which cells respond to a double-click?
Open the worksheet’s View Code window and edit the ranges inside Me.Range, such as AF23:AF375. Keep each range separated by a comma.
Will the date replace an existing formula?
Yes, if you select Yes in the confirmation dialog. Select No to leave the existing value or formula unchanged.
Why does double-clicking not insert a date?
Check that the code is in the target worksheet’s module, the cell is within one of the listed ranges, and macros are enabled for the trusted .xlsm workbook. Also check whether the cell is protected.




