VBA DATEVALUE Function

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

What is VBA DATEVALUE Function

how to use it

To use VBA's DATEVALUE function you need to understand its syntax and arguments:

Syntax

DateValue(Date)

Arguments

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

Example to use DATEVALUE Function in VBA

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

Below are some important points which you need to take care while using DATEVALUE function in VBA.

  • 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

About the Author

puneet one point one

Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can find him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.