VBA CDBL Function (Syntax + Example)

puneet-gogia-excel-champs

- Written by Puneet

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:

example-vba-cdbl-function
Sub example_CDBL()
Range("B1").Value = CDbl(Range("A1") * Range("A2"))
End Sub

In the above example, we used the value from cells A1 and A2 and then multiply them and then we used the CDATE function to convert that value into double data type and it returned 31.9506 in the result.

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.
Last Updated: June 22, 2023