Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA Today's Date: Insert, Format, and Use It

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To put today's date into a cell with Excel VBA, use Date (the current system date) or Now (date plus the current time) — for example Range("A1").Value = Date. That single line writes the date as a real Excel date value, so it sorts, filters and calculates correctly instead of behaving like text. You can also format it, stamp it into the active cell, or write it as plain string text when you need a fixed label. Everything below is written for the standard Visual Basic for Applications editor inside desktop Excel for Windows or Mac; the editor is not available in Excel for the web, so you need the desktop application to run these examples.

What You'll Need

  • Desktop Excel (Windows or Mac). VBA macros do not run in Excel for the web.
  • The Developer tab visible: File > Options > Customize Ribbon and tick Developer in the right-hand list. On Mac, Excel > Preferences > Ribbon & Toolbar. Labels can differ slightly by version and region.
  • An open workbook where you are comfortable saving macros — a .xlsm workbook, or a test file you can throw away.
  • Macro security set permissively enough to run your own code: Developer > Macro Security and choose to enable macros with notification, then click Enable Content when the yellow bar appears.

Step-by-Step

  1. Open the editor. Press Alt+F11 on Windows (on Mac, Opt+F11), or click Developer > Visual Basic. If the Developer tab is missing, see the What You'll Need section.
  2. Insert a module. In the editor choose Insert > Module. A blank code window appears. Modules hold general macros that any sheet can call, which is what you want for date helpers.
  3. Write the simplest version. Paste this and press F5 to run it:
    Sub PutTodaysDate()
        Range("A1").Value = Date
    End Sub
    Date returns the current date from your computer's clock. The cell now holds a genuine date serial number, not a string, so it will display according to the cell's number format.
  4. Choose Date or Now. Use Date when you only want the day. Use Now when you want the date and time together, for example Range("B1").Value = Now. Both read the system clock each time the macro runs, so the value is fresh on every run rather than frozen.
  5. Control the display format. Assign a number format so the cell shows what you expect, regardless of regional display settings:
    With Range("A1")
        .Value = Date
        .NumberFormat = "dd/mm/yyyy"
    End With
    Swap in "mm/dd/yyyy", "yyyy-mm-dd" or "dd mmm yyyy" as needed. Keep the value as a real date; format only changes how it looks.
  6. Stamp the active cell. To drop the date wherever the cursor happens to be, use ActiveCell.Value = Date. If you record a macro while typing today's date into a cell, Excel will hard-code that particular day — replace the literal with Date so the macro stays current.
  7. Write it into a named sheet reliably. Refer to the sheet by name rather than relying on whichever sheet is active: Worksheets("Log").Range("C5").Value = Date. If the sheet name might change, refer to it by its code name in the editor's Properties window.
  8. Append to a running list. For a log where each run adds the next row, find the first empty row and write there:
    With Worksheets("Log")
        Dim r As Long
        r = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Cells(r, 1).Value = Date
    End With
    This puts a new date under the last used entry in column A.
  9. Turn it into text when you need a fixed label. If you deliberately want a non-date string (for a filename, say), wrap it with Format: Range("D1").Value = Format(Date, "yyyy-mm-dd"). Use this sparingly — text dates do not sort or calculate like real dates.
  10. Save as macro-enabled. Use File > Save As and pick Excel Macro-Enabled Workbook (*.xlsm). A normal .xlsx save silently discards the module.

Common Mistakes

  • Using quotes around Date. Range("A1").Value = "Date" writes the word Date, not the current date. Only the bare, unquoted Date keyword returns today's date.
  • Recording instead of writing. Recorder output stores the literal date you typed. It works today and is wrong tomorrow.
  • Confusing display with value. Formatting a cell does not change what is stored; but typing an apostrophe before the date does turn it into text. Check with a formula like =ISNUMBER(A1) — a real date returns TRUE.
  • Assuming the format follows the user. A macro setting dd/mm/yyyy shows day first even for a user whose Windows region is set to month first. Decide deliberately which format the workbook should show.
  • Saving as .xlsx. The macros vanish on save, which looks like the code never worked.
  • Trusting the clock. Date reads the machine's system date. A wrong PC clock produces a wrong date with no error.

Tips

  • Store dates as dates and only format for display; you keep sorting, filtering, date arithmetic and pivot grouping.
  • For European-style day/month/year, Format(Date, "dd/mm/yyyy") gives a predictable text version, while NumberFormat keeps it a genuine date — choose based on whether you need to calculate with it.
  • If you want today's date to stay put once written, that is exactly what a plain Value = Date does — it does not refresh later. Reserve the volatile approach (writing on open or on edit) for cells you want to update each time.
  • Add a comment or label next to stamps so anyone reading the sheet knows the entry is a macro-generated date.
  • Test new macros in a copy of the workbook before running them on live data.

Troubleshooting

The macro does nothing. Check the yellow security bar and click Enable Content. Confirm the code sits in a module, not in a sheet's code pane, and that the sub name is not misspelled. Run it with F5 while inside the procedure.

You get a "Cannot run the macro" or macros are disabled message. Macro security settings are blocking it. Open Developer > Macro Security and allow macros with notification, close and reopen the file, then enable. Only do this for files you trust.

The cell shows a number like 46000. The cell is formatted as General. Set .NumberFormat or use Home > Number Format and pick a date format.

The date looks like text in reverse. If the cell cannot be parsed as a date, Excel may store it as a string. Clear it, reassign the value with Date, and apply a date number format.

"Sub or Function not defined" on Save As. Keep the file as .xlsm; changing extension back to .xlsx removes the project and the error returns.

Wrong date entirely. Fix the computer's clock and time zone in system settings, then run the macro again — the code itself is fine.

Nothing works at all and the Developer tab is absent. You may be using Excel for the web, which does not run VBA. Open the file in desktop Excel instead.

Frequently Asked Questions

What is the difference between Date and Now in VBA?

Date returns only the current date. Now returns the date and the current time together. Both read the computer's clock when the code runs.

How do I insert today's date without a macro?

Press Ctrl+; (semicolon) in the cell. That inserts the current date as a static value; Ctrl+Shift+; inserts the current time.

Does Date update automatically when the worksheet changes?

No. A value written by the macro stays as written. To refresh it, the macro must run again.

Can I stop an apostrophe from turning the date into text?

Write the date as a real value with .Value = Date and apply a number format, rather than typing it with a leading apostrophe.

Will these macros run on Mac?

Yes, VBA works in desktop Excel for Mac. Menu names for macro security and saving differ slightly, and .xlsm is still the required format.

How do I format the date as YYYY-MM-DD in VBA?

Set .NumberFormat = "yyyy-mm-dd" to keep it a real date, or use Format(Date, "yyyy-mm-dd") if you deliberately need a text string.