How to use the VBA DATEVALUE Function (Syntax + Example)

HomeVBA Functions LIST (Category Wise)How to use the VBA DATEVALUE Function (Syntax + Example)

The VBA DATEVALUE function is listed under the date category of VBA functions. When you use it in a VBA code, it can return date from a text representing a date. In simple words, it can convert a date into an actual date which is stored as a text. If there 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 VBA DATEVALUE function, you need to go through the below example where we have written a vba code by using it:

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 the cell A1 and it has converted that data into an actual date in the 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.

Related Functions

DATE | DATEADD | DATEDIFF | DATEPART | DATESERIAL | DAY | MONTH | MONTHNAME | WEEKDAY | WEEKDAYNAME | YEAR