Home

VBA Data Types: Currency

 

Introduction

The Currency data type is used to deal with monetary values. Here is an example of declaring it:

Sub Exercise()
    Dim StartingSalary As Currency
End Sub

Instead of using the As Currency expression, you can use @ as the type character to declare a currency variable. Here is an example of declaring it:

Sub Exercise()
    Dim StartingSalary@
End Sub

A variable declared with the Currency keyword can store a value between 922,337,203,685,477.5808 and 922,337,203,685,477.5807. Once again, keep in mind that the commas here are used only to make the number easy to read. Don't use the commas in a number in your code. Also, when assigning a value to a currency-based variable, do not use the currency symbol.

Here is an example of assigning a currency number to a variable:

Sub Exercise()
    Dim StartingSalary As Currency
    
    StartingSalary = 66500
End Sub

If you want to convert a value to currency, call the CCur() function with the following formula:

Number = CCur(Value to Convert)

To perform this conversion, enter the value in the parentheses of CCur().

 
 
     
 

Home Copyright © 2009-2010 FunctionX, Inc.