VBA CDATE Function

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

What is VBA CDATE Function

The VBA CDATE function is listed under the data type conversion category of VBA functions. When you use it in a VBA code, it converts an expression into the date data type. In simple words, with date data type it can hold a value that includes date and time as per VBA’s valid date and time system.

how to use it

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

Syntax

CDate(Expression)

Arguments

  • Expression: The value which you want to convert to the date data type.

Example to use CDATE Function in VBA

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

Sub example_CDATE()
Range("B1").Value = CDate(Range("A1"))
End Sub

In the above example, we have used the value from the cell A1 where we have a number (8.5694) and then we have used the CDATE function to convert that value into date data type and it has returned 7/8/2018 0:00 in the result.

Notes

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

  • It can interpret text representations of dates and times that can be recognised by VBA as Excel date and time format.
  • A value which can’t be converted as date and time, VBA returns the run-time 13 error.

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.