Excel VBA CDbl Function

VBA CDbl Function: The CDbl function in VBA converts an expression into a Double data type.

Syntax

CDbl (Expression)

Parameter

Expression (required) - This parameter represents the expression that that you want to convert to a Double.

Return

This function returns a double precision floating point number after converting the given expression into double data type.

Example 1

Sub CDblFunction_Example1()
 ' Converting the values Into doubles
 Dim dbl As Double
 dbl = CDbl("6.00001")
 ' dbl variable will return $6.00
 Cells(1, 1).Value = dbl
 End Sub 

Output

$6.00

VBA CDbl Function

Example 2

Sub CDblFunction_Example2()
 ' Converting the values Into doubles
 Dim dbl As Double
 dbl = CDbl(1.0987 * 1.0987)
 ' dbl variable will return $1.21
 Cells(1, 1).Value = dbl
 End Sub 

Output

$1.21

VBA CDbl Function

Example 3

Sub CDblFunction_Example3()
 ' Converting the values Into doubles
 Dim dbl As Double
 dbl = CDbl("Hello World")
 ' dbl variable will return type miss match error
 Cells(1, 1).Value = dbl 
 End Sub 

Output

VBA CDbl Function