The VBA CDBL function is listed under the data type conversion category of VBA functions. When you use it in a VBA code, it converts a value into a double data type. In simple words, double data type expression holds a number ranging from -1.79769313486231570E+308 through -4.94065645841246544E-324 for negative values and from 4.94065645841246544E-324 through 1.79769313486231570E+308 for positive values.
Syntax
CDbl(Expression)
Arguments
- Expression: The value that you want to convert to the double data type.
Example
To practically understand how to use the VBA CDBL function, you need to go through the below example where we have written a vba code by using it:
Sub example_CDBL()
Range("B1").Value = CDbl(Range("A1") * Range("A2"))
End Sub
In the above example, we used the values from cells A1 and A2 and multiplied them. Then, we used the CDATE function to convert that value into a double data type, and the result was 31.9506.
Notes
- If the value specified is a value other than a number or a number that can’t be recognized as a number, VBA will return the run-time 13 error.
- It will also return an error if the value supplied is out of the range of the double data type.
- Back to the Excel VBA / VBA Functions