Return to VBA Code Examples

VBA CDec Function

This tutorial will demonstrate how to use the CDec VBA function.

CDec Function

VBA CDec Convert Expression to Decimal

The VBA CDec function converts an expression to a decimal data type. The decimal data type is actually a subtype of the variant data type.

VBA CDec Converting Strings to Decimals

The VBA CDec function can be used to convert strings to decimals if the characters in the string have a meaning as numbers.

VBA CDec Run-Time Error 13 Type Mismatch

Using VBA CDec function with strings that contain non-numerical characters or characters that don’t have meaning in numerical context will result in a Run-Time error ’13’: Type mismatch.

VBA CDec Run-Time Error 6 Overflow

Using VBA CDec function with strings that result in a value smaller or bigger than the expected decimal will result in a Run-Time error ’6’: Overflow. A Decimal number should be between -7.9 E28 and +7.9 E28.

VBA CDec Regional Settings

VBA CDec function has different behavior converting strings with comma or dot.  It uses the Regional Settings of the operating system for decimal separator and digit separator.


VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!