VBA NOW Function

VBA NOW Function in Excel

VBA Now Function in Excel is a built-in function in MS Excel. It does not take any input arguments or parameters. It returns the current system date and time. It is a ‘Data and Time’ type function. Default format of the Now Function is ‘mm/dd/yyyy HH:MM:SS AM/PM’. The Now function we can use in worksheet as well. The VBA Now Function can be used in either procedure or function in a VBA editor window in Excel. We can use the VBA Now Function any number of times in any number of procedures or functions. In the following section we learn what is the syntax and parameters of the Now Function, where we can use this VBA Now Function, real-time examples and Instructions.

Syntax of VBA Now Function

The syntax of the VBA Now Function is

NOW()

In the above syntax parentheses is optional. If there is no argument, then no need to specify parentheses.

Parameters or Arguments

There are no parameters or arguments for the Now Function.

Where we can apply or use the VBA Now Function?

We can use this VBA date function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

Example 1: Display current system date and time on the screen

Here is a simple example of the VBA Now Function. This below example macro uses the Now Function and displays the current system date and time.

'Display Current System Date and Time on the screen
Sub VBA_Now_Function_Ex1()
    
    'Variable declaration
    Dim sCurrentDateTime As Date
    
    'Assign current system date to variable
    sCurrentDateTime = Now()
    MsgBox sCurrentDateTime, vbInformation, "Current System Date & Time"
    
End Sub 

In the above example ‘sCurrentDate’ declared as a Date data type. This variable ‘sCurrentDate’ now contains the current system date and time.
Output: It displays current system date and time on the screen. Here is the screen shot of first example output.
VBA NOW Function Example 1

 

Example 2: Display current system date and Time on the Worksheet

Here is another example of the VBA Now Function. This below example macro uses the Now Function and displays the current system date and time on the Worksheet named ‘VBAf1.com’ in Range B18.

'Display Current System Date and Time on the Worksheet
Sub VBA_Now_Function_Ex2()
    
    'Variable declaration
    Dim sCurrentDateTime As Date
    
    'Assign current system date to variable
    sCurrentDateTime = Now
    Sheets("VBAF1.com").Range("B18") = sCurrentDateTime
    'or
    'Sheets("Sheet1").Cells(18, 2) = sCurrentDateTime
    
End Sub

Note: Difference between first output and second output is format of the date and time.
Output: Here is the screen shot of second example output.
VBA NOW Function Example 2

Example 3: Change Date and Time Format

Here is one more example with VBA Now Function. This below example macro uses the Now Function and changes the format of the date and time. Finally, it displays the current system date and time on the screen.

'Format and Display Current System Date and Time on the screen
Sub VBA_Now_Function_Ex3()
    
    'Variable declaration
    Dim sCurrentDateTime As Date
    
    'Assign current system date to a
    sCurrentDateTime = Now
    MsgBox Format(sCurrentDateTime, "DD/MMM/YYYY HH:MM:SS"), vbInformation, "Current System Date & Time"
    
End Sub

Output: Here is the screen shot of third example output.
VBA NOW Function Example 3

Download File

Click on following link to download free example excel workbook to learn more about VBA Now function.

VBA Now Function Examples

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays in Excel Blog

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers

Leave a Reply