VBA DATEVALUE Function

VBA DATEVALUE Function in Excel

VBA DateValue Function in Excel is a built-in function in MS Excel. It has one input argument or parameter. VBA DateValue Function returns the date value representing date for a string. It is a ‘Data and Time’ type function. It can be used in either procedure or function in a VBA editor window in Excel. We can use the VBA DateValue 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 DateValue function.We will also see where we can use this VBA DateValue Function and real-time examples.

Syntax of VBA DateValue Function in Excel

The syntax of the VBA DateValue Function is

DATEVALUE(date_value)

Parameters or Arguments

There is one parameter or argument for the DateValue Function in VBA. That is nothing but ‘date_value’ parameter. It is a mandatory argument. It represents date in string format.

Where we can apply or use the VBA DateValue Function?

We can use this DateValue Function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007 and Excel 2003. We can also use in 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: Convert the given input string to a valid date and display on the screen

Here is a simple example of the VBA DateValue Function. This below example macro uses the DateValue Function and displays date for the specified string. In this case specified string represents date.

Sub VBA_DATEVALUE_Function_Example1()
'Convert the given input string to a valid date and display on the screen
    
    'Variable declaration
    Dim dDate As Date
    
    'Assign date to a variable
    dDate = DateValue("May 20, 2017")
    
    'Display output on the screen
    MsgBox "Specified Date is: " & dDate, vbInformation, "VBA DATEVALUE Function"
    
End Sub 

In the above example ‘dDate declared as ‘Date’ data type. And DATEVALUE is a vba function. This variable ‘dDate’ now contains the date.
Output:Here is the screen shot of first example output.
VBA DATEVALUE Function Example 1

Example 2: Convert the given input string to a valid time and display on the Worksheet

Here is another example of the VBA DateValue Function. This below example macro uses the DateValue Function and displays date for the specified string(date). Now, it displays on the Worksheet named ‘VBAF1.Com’ at Range ‘B20’.

Sub VBA_DATEVALUE_Function_Example2()
'Convert the given input string to a valid date and display on the Worksheet
    
    'Variable declaration
    Dim dDate As Date
    
    'Assign date to a variable
    dDate = DateValue("May 20, 2017")
    
    'Display output on the screen
    Sheets("VBAF1.COM").Range("B20") = "Specified Date is: " & dDate
    
End Sub 

Output: Here is the screen shot of second example output.
VBA DATEVALUE Function Example 2

Download File:

Click on following link to download free example excel workbook to learn more about the DateValue Function.

VBA DateValue 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