VBA DATEVALUE Function (Syntax + Example)

Last Updated: June 22, 2023
puneet-gogia-excel-champs

- Written by Puneet

The VBA DATEVALUE function is listed under the date category of VBA functions. When you use it in a VBA code, it can return a date from a text representing a date. In simple words, it can convert a date into an actual date which is stored as text. If there is a time with that date it will ignore it. It’s just like the DATEVALUE function in the worksheet.

Syntax

DateValue(Date)

Arguments

  • Date: A string that represents a valid date as per VBA.

Example

To practically understand how to use the VBA DATEVALUE function, you need to go through the below example where we have written a vba code by using it:

example-vba-datevalue-function
Sub example_DATEVALUE()
Range("B1").Value = DateValue(Range("A1"))
End Sub

In the above example, we have used the DATEVALUE to convert a date stored as text in cell A1 and it has converted that data into an actual date in cell B1.

Notes

  • If the value specified is a value other than a date or a date that can’t be recognized as a date, VBA will return the run-time 13 error.
  • And if the date is NULL, it will return NULL.