The VBA CDbl Function


The VBA CDbl function converts an expression into a Double data type (i.e. into a double precision floating point number).

The syntax of the function is:

CDbl( Expression )

Where the Expression argument is the expression that that you want to convert to a Double.

VBA CDbl Function Examples

The following VBA code shows how the CDbl function is used to convert text strings and numeric values into double precision floating point numbers.

' Convert strings and numeric values into Doubles
Dim dbl1 As Double
Dim dbl2 As Double
dbl1 = CDbl( "5.00000001" )
' dbl1 is now equal to 5.00000001
dbl2 = CDbl( 1.00001 * 1.00001 )
' dbl2 is now equal to 1.0000200001

After running the above VBA code, the variable dbl1 = 5.00000001 and the variable dbl2 = 1.0000200001.

VBA CDbl Function Error

If the CDbl function is supplied with a text string that cannot be converted into a numeric value, it will return the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box