How to Add a Timestamp to the Next Row in Excel Using a Button
Question details
The user needs a way to insert the current time into the next available empty row of a specific column each time a designated button is clicked.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating data entry, time-tracking, or logging tasks by recording the exact time of an event with a single click.
- Observed behavior
- A VBA macro assigns the current system time to the next blank row in Column A, triggered seamlessly via a Form Control button on the worksheet.
Ensure the Developer tab is enabled in your spreadsheet software to access the Visual Basic Editor and Form Controls. Always save your workbook as a Macro-Enabled Workbook (.xlsm) to prevent losing your VBA code.
Create a Timestamp Macro and Assign it to a Button
Use a short VBA script combined with a Form Control button to automate the process of finding the next empty row and inserting a static timestamp.
This solution relies on the COUNTA function within VBA to count the number of non-empty cells in a column, effectively locating the next blank row. The 'Now' function is used to retrieve the exact system date and time.
Select the entire Column A by clicking the column header. Right-click, select 'Format Cells', and choose a Date or Time format that suits your needs.
Press 'ALT + F11' on your keyboard to open the Visual Basic for Applications (VBA) Editor. In the top menu, click 'Insert' and select 'Module' to create a new blank module.
In the new module window, type or paste the following code: Sub TimeStamp() Range("A" & [COUNTA(A:A)] + 1).Value = Now End Sub. Close the VBA editor.
Navigate to the 'Developer' tab on the main Excel ribbon. Click 'Insert', select 'Button (Form Control)', and click anywhere on your worksheet to draw the button.
An 'Assign Macro' dialog box will immediately appear. Select 'TimeStamp' from the list and click 'OK'. Finally, go to File > Save As, and choose 'Excel Macro-Enabled Workbook (*.xlsm)' to save your progress.

Use WPS Spreadsheet to Run VBA Macros Seamlessly
WPS Spreadsheet fully supports VBA macros, allowing you to create timestamp buttons, write scripts, and automate repetitive data entry tasks exactly as you would in Microsoft Excel.
- 1. Download and Install: Download WPS Office and open your existing spreadsheet in WPS Spreadsheet.
- 2. Open the VBA Editor: Navigate to the Developer tab on the ribbon and click 'VBA Editor' to open the scripting environment.
- 3. Insert the Code: Go to Insert > Module and paste the TimeStamp macro script.
- 4. Add a Button: From the Developer tab, click 'Insert' to place a Button on your sheet and assign the TimeStamp macro to it.
- 5. Click to Run: Click the newly created button to instantly log the current time in the next available row.

Frequently Asked Questions
Why does the macro overwrite existing data instead of going to the next blank row?
The macro relies on the COUNTA function, which counts the total number of non-empty cells in the column. If you have scattered blank cells within your data in Column A, the count will be lower than the actual last row number, causing the macro to overwrite existing rows. Ensure there are no empty gaps in your column for this specific macro to work.
Can I add the timestamp to a column other than Column A?
Yes, you can easily modify the VBA code to target a different column. Simply change the letter "A" in the script. For example, to target Column C, change the code to: Range("C" & [COUNTA(C:C)] + 1).Value = Now.
Why does my newly inserted timestamp look like a random string of numbers?
Excel and WPS Spreadsheet store dates and times as serial numbers. If the destination cell is formatted as 'General', it will display this underlying number. To fix this, right-click the column, select 'Format Cells', and choose your preferred 'Time' or 'Date' format.
How do I stop the timestamp from updating every time I type something else?
If you are using the =NOW() formula in a cell, it is highly volatile and will update upon any sheet calculation. The VBA macro method described above solves this issue because it evaluates the 'Now' command at the moment of the click and pastes it as a hardcoded, static value that will never auto-update.




