What is VBA CDBL Function
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.
how to use it
To use VBA's CDBL function you need to understand its syntax and arguments:
- Expression: The value that you want to convert to the double data type.
Example to use CDBL Function in VBA
To practically understand how to use 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 have used the value from the cell A1 and A2 and then multiply them and then we have used the CDATE function to convert that value into double data type and it has returned 31.9506 in the result.
Below are some important points which you need to take care while using CDBL function in VBA.
- If the value specified is a value other than a number or a number which can’t be recognized as a number, VBA will return the run-time 13 error.
- It will also returns an error if the value supplied is out of the range of double data type.
About the Author
Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can ﬁnd him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.