Use Excel VBA to Autofill Dates Based on Column B
Question details
Fill column A with dates for rows containing data in column B, even when the number of rows changes.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A spreadsheet changes in length, and the user wants either a date formula that updates daily or a fixed date value for populated rows.
- Observed behavior
- Column A should receive dates for rows where column B contains data, up to the last populated row in column B.
These examples assume row 1 contains headers and data begins in row 2; change the starting row in the code if needed. Check whether column A already contains values, and save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if you want to retain the macro.
Fill column A with a dynamic TODAY formula
Use this method when the displayed date should update each day.
The macro finds the last populated row in column B and checks each row individually, so gaps in column B are skipped. It overwrites existing values in column A for matching rows.
In Excel, open the target worksheet, select Developer > Visual Basic, and choose Insert > Module.
Paste this code into the module: Sub FillTodayFormulas() Dim ws As Worksheet Dim lastRow As Long, r As Long Set ws = ActiveSheet lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row For r = 2 To lastRow If Len(ws.Cells(r, "B").Value) > 0 Then ws.Cells(r, "A").Formula = "=TODAY()" End If Next r End Sub
Return to the target worksheet, choose Developer > Macros, select FillTodayFormulas, and click Run. If necessary, select column A and choose Home > Number Format > Short Date.

Insert fixed dates in empty column A cells
Use this method to preserve a date value instead of updating it every day.
Work with date formulas in WPS Spreadsheet
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open compatible Excel files and use date formulas while moving between Office applications; VBA macro support may vary by WPS edition and configuration.

Frequently Asked Questions
Why do the dates change each day?
The formula =TODAY() returns the current date when Excel recalculates. Use the fixed-date macro with the VBA Date value if the date should stay unchanged.
Will the macro fill dates automatically when I add rows?
Not by itself. After adding data to column B, activate the worksheet and run the macro again from Developer > Macros.
What happens if column B has blank rows?
Both macros check each row through the last populated row and skip blank cells in column B. They do not clear any existing values in column A for those rows.
How do I keep the macro in my workbook?
Choose File > Save As and select Excel Macro-Enabled Workbook (.xlsm). Enable macros when prompted only if you trust the workbook.
What does xlUp do in the last-row code?
The expression ws.Cells(ws.Rows.Count, "B").End(xlUp).Row finds the last populated cell by moving upward from the bottom of column B. The constant uses a lowercase L after the x, not the number 1.




