# VBA CDEC Function (Syntax + Example)

Last Updated: June 22, 2023

- Written by Puneet

Contents

The VBA CDEC function is listed under the data type conversion category of VBA functions. When you use it in a VBA code, it converts a number into a decimal data type. In simple words, with the decimal data type, a number can have 28 decimals where the largest value is +/-7.9228162514264337593543950335, and the smallest nonzero value is +/-0.0000000000000000000000000001.

CDec(Expression)

## Arguments

• Expression: The value which you want to convert into the decimal data type.

## Example

To practically understand how to use the VBA CDEC function, you need to go through the below example where we have written a vba code by using it:

``````Sub example_CDEC()
Range("B1").Value = CDec(Range("A1") / Range("A2"))
End Sub``````

In the above example, we have divided the value from cell A1 (10) with the value from cell A2 (9) and then we used the CDEC function to convert that value into decimal data type and it returned 1.11111111111111 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 decimal data type.