Excel VBA Current Date and Time: Use Now, Date, and Time

VBA & macros · Updated November 3, 2026

Excel VBA Current Date and Time: Use Now, Date, and Time

In Excel VBA, use Now to get the current date and time, Date for the current date, or Time for the current time. For example, assigning Now to a worksheet cell writes a timestamp at the moment the macro runs; it does not keep updating by itself.

Which VBA function should you use?

These built-in VBA functions all read the computer’s current system date and time, but they return different parts of it:

  • Now returns both the current date and current time.
  • Date returns the current date, with the time portion set to midnight.
  • Time returns the current time, without a meaningful date portion.

For a complete timestamp, Now is usually the right choice. Use Date when recording a day without needing the time, such as an order date. Use Time for a time-of-day entry, such as a shift start. You can assign any of these values to a variable, a worksheet cell, or another VBA property that accepts a date or time.

The values come from the operating system clock, not from a special Excel clock or an online time service. If the computer’s date, time, or time zone is incorrect, the VBA result can be incorrect too. These functions do not automatically convert the result to another time zone.

Write a timestamp to a worksheet cell

To put the current date and time in cell A1 of the active worksheet, open the Visual Basic Editor, insert a standard module, and add a procedure like this. Change the target cell if needed.

Option Explicit

Sub StampCurrentDateTime()
    Dim target As Range

    ' Use cell A1 on the currently active worksheet.
    Set target = ActiveSheet.Range("A1")

    ' Capture the date and time when this macro runs.
    target.Value = Now

    ' Display both the date and the time.
    target.NumberFormat = "yyyy-mm-dd hh:mm:ss"
End Sub

The procedure stores a value and then applies a display format. The format shows a four-digit year, month, day, hours, minutes, and seconds. It does not change the underlying timestamp. If your worksheet is protected, or the target cell is otherwise unavailable for editing, the assignment may fail until you address that restriction.

For a workbook with several sheets, you may prefer to name the worksheet explicitly instead of relying on whichever sheet happens to be active. Replace ActiveSheet with a worksheet reference such as ThisWorkbook.Worksheets("Log"), using the actual sheet tab name. This makes the destination predictable when someone runs the macro from another sheet.

Write only the date, only the time, or both

Each function can be written to its own cell. The following example uses the active worksheet and applies a suitable display format to each value:

Option Explicit

Sub WriteDateAndTimeParts()
    Dim ws As Worksheet

    ' Work on the currently active worksheet.
    Set ws = ActiveSheet

    ' Store date, time, and complete timestamp separately.
    ws.Range("A1").Value = Date
    ws.Range("B1").Value = Time
    ws.Range("C1").Value = Now

    ' Display only the relevant parts in each cell.
    ws.Range("A1").NumberFormat = "yyyy-mm-dd"
    ws.Range("B1").NumberFormat = "hh:mm:ss"
    ws.Range("C1").NumberFormat = "yyyy-mm-dd hh:mm:ss"
End Sub

In this example, A1 contains a date whose time component is midnight, B1 contains a time value, and C1 contains the full date and time. Formatting B1 to show only hours and minutes does not turn it into text; Excel still holds a numeric time value that can be used in calculations.

Excel stores dates and times as serial numbers: the whole-number portion represents the date and the fractional portion represents the time of day. That is why number formatting can show the same underlying value in different ways. It also explains why a time-only value can appear as a decimal or an unexpected date if the cell has an unsuitable number format.

Format the result for people reading the sheet

A stored timestamp may not look the way you expect until you set its number format. In VBA, a cell’s NumberFormat property accepts an Excel number-format string. Common choices include:

  • yyyy-mm-dd for a clear, sortable date such as 2026-11-02.
  • m/d/yyyy for a compact date, displayed according to Excel’s interpretation and regional settings.
  • hh:mm for hours and minutes in a 24-hour clock.
  • h:mm AM/PM for a 12-hour clock with an AM or PM indicator.
  • yyyy-mm-dd hh:mm:ss for a timestamp that includes seconds.

In Excel number formats, mm can represent a month or minutes depending on its position in the format. In a time section following hours, as in hh:mm:ss, it represents minutes. For dates, it represents the month. If the display is confusing, check the complete format string and verify whether the cell holds a date, a time, or both.

Formatting is particularly useful for avoiding ambiguity. A date such as 4/5/2026 can mean April 5 or May 4 depending on regional conventions. A year-first format such as yyyy-mm-dd is easier to interpret across locales, although the way Excel displays some formats can still depend on the user’s regional settings.

Does the VBA timestamp update automatically?

No. A macro that assigns Now to a cell writes the value returned when that line executes. The cell then holds a fixed timestamp unless another action or macro changes it. This is often desirable for audit trails, completed-task logs, or recording when a row was entered: a historical record should not silently change whenever the workbook recalculates.

If you need a visibly changing clock or a current time that refreshes during recalculation, a worksheet formula may be more appropriate. For example, with the result intended for cell A1, enter =NOW() in A1. The worksheet function is volatile, so Excel recalculates it when calculation occurs; it is not a continuously ticking clock that updates every second. The exact refresh behavior depends on the workbook’s calculation settings and recalculation events.

Another option is to run a macro again when a specific event occurs, such as when a user edits a cell. That approach can record a fixed timestamp at the moment of the event, but it requires event code and careful testing so it does not overwrite earlier records. Choose based on the meaning of the value: a live current-time display, a value refreshed by calculation, and a permanent entry-time stamp are different requirements.

How to add and run the macro

In Excel for Microsoft 365 on Windows, use Developer > Visual Basic to open the editor. If the Developer tab is missing, enable it through File > Options > Customize Ribbon, then select the Developer check box. In the editor, choose Insert > Module, paste the procedure into the module, and return to Excel. You can run a macro with Alt+F8, select its name, and choose Run. Alt+F11 opens the Visual Basic Editor on Windows.

On a Mac, use the Developer tab’s Visual Basic and Macros commands when available. The keyboard shortcut for the Visual Basic Editor can depend on the Mac keyboard and function-key settings; on many keyboards, Option+F11 works, sometimes with Fn as well. A macro-enabled workbook must be saved in a format that supports macros, such as .xlsm. Excel for the web can open a workbook containing VBA, but it cannot create, edit, or run VBA macros; use the desktop app for those tasks.

Macros may be blocked by security settings, and you should only enable macros in files from sources you trust. Before running a macro, save a copy of the workbook. VBA changes cannot be undone with Ctrl+Z, so a backup is useful if the code writes to the wrong cells or replaces existing data.

Common problems and how to avoid them

  • The cell shows a number instead of a date. Excel may be displaying the serial value using a General or numeric format. Apply an appropriate date or date-and-time number format.
  • The time looks like a date or a fraction. The value may be correct but formatted for the wrong purpose. Use a time format such as hh:mm:ss.
  • The timestamp is different from another computer’s. Now uses the local system clock and its configured time zone. Check the computer’s clock and time-zone settings; VBA does not independently verify the time.
  • The macro writes to the wrong sheet. ActiveSheet means the sheet selected when the macro runs. Reference a named worksheet if the destination must not depend on the active tab.
  • The code does not run. Confirm that the workbook is macro-enabled, that macros are allowed under your organization’s security policy, and that the code is in a standard module if you are running it directly from the Macros dialog.
  • The displayed timestamp has no seconds. The cell format may show only hours and minutes. Include :ss in the format to display seconds; the stored value can contain seconds even when they are hidden.

A further distinction matters when passing values around in VBA. A cell’s Value property can expose a date as a VBA Date value, while Value2 avoids the Date and Currency subtypes and returns the underlying numeric value for date-like cells. For ordinary timestamp entry and display, Value is straightforward. Use Value2 when your code specifically needs the raw Excel serial number and you understand how it will be interpreted.

Frequently Asked Questions

What is the VBA code for the current date and time in Excel?
Use Now. To put it in a cell, assign it to a range, such as Range("A1").Value = Now, and apply a date-and-time number format if the display needs adjustment.

What is the difference between Now and Date in VBA?
Now returns the current date and time. Date returns the current date with the time portion at midnight. Use Time when you need the current time of day without the date.

How do I insert a timestamp that will not change?
Run a macro that assigns Now to the cell. That writes a fixed value at run time. A worksheet function such as =NOW() is recalculated, so it is not a permanent historical stamp.

Can Excel VBA get the current time in another time zone?
Now reads the computer’s local system date and time; it does not offer a built-in time-zone conversion. Converting to another zone requires additional logic or a trusted time-zone source, including appropriate handling of daylight-saving rules.

Why does Now show a decimal number in my cell?
Excel stores dates and times as serial numbers. Apply a date-and-time number format to display the value as a readable timestamp instead of its underlying number.

Can I run this VBA macro in Excel for the web?
No. Excel for the web does not run VBA macros. Open the workbook in the Excel desktop application to edit or run VBA; the web app can still display and edit many workbook contents.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.