Learn Excel - Simplify Life with Excel Concepts

Excel CDec Function (VBA)

CDec Function VBA Code

How to use the CDec Function (VBA)

This Excel tutorial explains how to use the Excel CDec function with syntax and examples using VBA.

SUMMARY:

The Excel VBA CDec function converts an expression into a Decimal value.

For example,

  • The VBA Code CDec("2.00000001") would return 2.00000001
  • The VBA Code CDec(2.00001 *2.00001) would return 4.0000400001

PURPOSE:

To converts a value to decimal number.

RETURN VALUE:

The CDec function returns a Decimal value.

SYNTAX:

CDec( expression )

ARGUMENTS:

The CDec function syntax has the following arguments:

  • expression: Required. The expression is that you want to convert to a decimal number.
    • The "expression" can be any number between -7.9 E28 and +7.9 E28
    • If "expression" is outside this range, then an error occurs.

REMARKS:

  • The CDec function can only be used in VBA code in Microsoft Excel.
  • The Decimal data type is a sub type of the Variant data type.
  • The CDec function always returns a variant whose value has been converted to a Decimal subtype.
  • An overflow error will occur if the value is out of range.
  • There does not actually exist a Decimal data type although it is possible to have a Variant data type, whose subtype is Decimal.

Useful Links: Link 1Link 2Link 3Link 4