The VBA CCur Function

Description

The VBA CCur function converts an expression into a Currency data type.

The syntax of the function is:

CCur( Expression )

Where the Expression argument is the expression that that you want to convert to a Currency.

Note that the Currency data type has a maximum of 15 digits to the left of the decimal place and a maximum of 4 digits to the right of the decimal place. It can hold values between -922,337,203,685,477.5808 and 922,337,203,685,477.5807


VBA CCur Function Examples

In the following VBA code, the CCur function is used to convert two different values into Currency data types.

' Convert Two Values Into Currency Data Types
Dim cur1 As Currency
Dim cur2 As Currency
cur1 = CCur( 15 )
' cur1 is now equal to 15
cur2 = CCur( 5.555555 )
' cur2 is now equal to 5.5556

After running the above VBA code, the variable cur1 = 15 and the variable cur2 = 5.5556.

Note that the value 5.555555 was rounded to four decimal places before being converted to a Currency data type.


VBA CCur Function Errors

If you supply the CCur function with a numeric value that is less than -922,337,203,685,477.5808 or greater than 922,337,203,685,477.5807, you will get the error:

Run-time error '6': Overflow

VBA Run Time Error 6 Message Box


If you supply the CCur function with a text string that cannot be converted to a number, you will get the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box