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.
- Expression: The value which you want to convert to the date data type.
To practically understand how to use the 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 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.
- It can interpret text representations of dates and times that can be recognized by VBA as Excel date and time format.
- A value that can’t be converted as date and time, VBA returns the run-time 13 error.
CBOOL | CBYTE | CCUR | CDBL | CDEC | CHR | CINT | CLNG | CSNG | CSTR | CVAR | FORMATCURRENCY | FORMATDATETIME | FORMATNUMBER | FORMATPERCENT | HEX | OCT | STR | VAL