VBA & Macro Problems

How to Automatically Keep the Previous Update Date in Excel with VBA

Maira MehtabMaira Mehtab Oct 23, 2026 870 views

Question details

The user wants to use a VBA macro and a form control button to record the current date in one cell while automatically shifting the existing date to another cell to maintain a history of updates.

How to Automatically Keep the Previous Update Date in Excel with VBA
Product
Excel
Device & OS
not provided
Scenario
Tracking document update history and timestamps.
Observed behavior
Manually updating a date cell overwrites the previous value; the goal is to preserve the last update date automatically when logging a new one.
Before you start

Ensure that the Developer tab is enabled in your Excel ribbon and that you have permission to run and save Macro-Enabled Workbooks (.xlsm).

Solution 1Recommended

Use a VBA Macro with a Form Control Button

Create a simple VBA script that shifts the current date to a 'previous' cell and inserts today's date into the 'current' cell, triggered by a clickable button.

This solution relies on a short VBA macro to check if a date already exists in the target cell. If it does, it moves that date to a secondary cell before updating the primary cell with the current date.

1
Format the Target Cells

Select cells A1 and A2 (or your chosen cells), right-click, choose 'Format Cells', and set them to your preferred Date format.

2
Open the VBA Editor

Press 'Alt + F11' on your keyboard to open the Visual Basic for Applications (VBA) editor. Go to 'Insert' > 'Module' to create a new standard module.

3
Insert the Macro Code

Copy and paste the following code into the module window: Sub SetUpdated() If Range("A1").Value <> "" Then Range("A2").Value = Range("A1").Value End If Range("A1").Value = Date End Sub

4
Add a Form Control Button

Close the VBA editor. Go to the Developer tab on the ribbon, click 'Insert', and choose 'Button (Form Control)'. Click and drag on your worksheet to draw the button.

5
Assign the Macro

When the 'Assign Macro' dialog appears automatically, select 'SetUpdated' from the list and click 'OK'. You can right-click the button to edit its text (e.g., 'Update Date').

6
Save as XLSM

Go to 'File' > 'Save As' and choose 'Excel Macro-Enabled Workbook (*.xlsm)' from the format dropdown to ensure your VBA code is saved permanently.

Use a VBA Macro with a Form Control Button
Tip: To track the exact time along with the date, replace 'Date' in the VBA code with 'Now' and adjust your cell formatting to display both date and time.
Efficient Data Tracking with WPS

Track Update Dates Easily in WPS Spreadsheet

WPS Spreadsheet fully supports VBA macros and Excel's .xlsm file formats, allowing you to implement customized date-tracking automation just like you would in Microsoft Excel.

  1. 1. Enable Developer Tools: Open your workbook in WPS Spreadsheet. Go to the 'Developer' tab on the top ribbon to access VBA and macro settings.
  2. 2. Write Your Macro: Click 'Visual Basic' or press Alt+F11, insert a new Module, and paste your update date tracking VBA code.
  3. 3. Insert a Control Button: Under the Developer tab, click 'Insert', select a Form Control Button, place it on the sheet, and assign your macro to it.
  4. 4. Save and Run: Save the file as a Macro-Enabled Workbook (.xlsm) and click your newly created button to update dates automatically.
Seamless compatibility with Microsoft Excel .xlsm files and VBA scriptsBuilt-in Developer tab for quick macro creation and editingLightweight application with high performance for data processingFree and familiar interface with no steep learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't my date update macro run when I click the button?

Ensure that macros are enabled in your Trust Center or security settings. Also, verify that the workbook is saved correctly as a Macro-Enabled Workbook (.xlsm), as standard .xlsx files cannot store VBA code.

Can I use different cells instead of A1 and A2?

Yes. Simply change the 'A1' and 'A2' references in the VBA code (e.g., Range("B5").Value) to the specific cell references you want to use for logging the current and previous dates.

Will this macro overwrite existing data in the previous date cell?

Yes, each time you run the macro by clicking the button, the date currently in the first cell replaces whatever data is in the second (previous date) cell.

Is there a way to record the exact time along with the date?

Yes, you can modify the VBA code to use the 'Now' function instead of the 'Date' function (e.g., Range("A1").Value = Now). This captures both the current date and the system time.