VBA CCur Function in Excel is categorizes as a Data Type Conversion function. It is a built-in function in Excel VBA. This VBA CCur function converts an expression to a Currency data type.
This function use in either procedure or function in a VBA editor window in Excel. We can use this VBA CCur Function in any number of times in any number of procedures or functions. In the following section you learn many topics. Like what is the syntax and parameters of the CCur function, where we can use this VBA CCur Function and it’s real-time examples.
- Overview
- Syntax of VBA CCur Function
- Parameters or Arguments
- Where we can apply or use VBA CCur Function?
- Example 1: Convert a Value(10.2) to Currency Data Type
- Example 2: Convert a Value(10.6) to Currency Data Type
- Example 3: Convert a Value(10.68647) to Currency Data Type
- Example 4: Convert a String(‘Example’) to Currency Data Type
- Instructions to Run VBA Macro Code
- Other Useful Resources
Syntax of VBA CCur Function:
The syntax of the CCur Function in VBA is
CCur(Expression)
The CCur function returns a currency data type value.
Parameters or Arguments:
The CCur function has one argument in Excel VBA.
where Expression: It is a mandatory argument. An expression argument represents a value. It is used to convert the value to a currency value.
Where we can apply or use VBA CCur Function?
We can use this CCur Function in VBA MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.
Example 1: Convert a Value(10.2) to Currency Data Type
Here is a simple example of the VBA CCur function. This below example converts an expression(10.2) to currency data type. It returns a value 10.
'Convert a Value(10.2) to Currency Data Type Sub VBA_CCur_Function_Ex1() 'Variable declaration Dim iValue As Integer Dim bResult As Currency iValue = 10.2 bResult = CCur(iValue) MsgBox "The value(10.2) in currency is : " & bResult, vbInformation, "VBA CCur Function" End Sub
Output: Here is the screen shot of the first example output.
Example 2: Convert a Value(10.6) to Currency Data Type
Here is a simple example of the VBA CCur function. This below example converts an expression(10.6) to currency data type. It returns a value 11.
'Convert a Value(10.6) to Currency Data Type Sub VBA_CCur_Function_Ex2() 'Variable declaration Dim iValue As Integer Dim bResult As Currency iValue = 10.6 bResult = CCur(iValue) MsgBox "The value(10.6) in currency is : " & bResult, vbInformation, "VBA CCur Function" End Sub
Output: Here is the screen shot of the second example output.
Example 3: Convert a Value(10.68647) to Currency Data Type
Here is a simple example of the VBA CCur function. This below example converts an expression(10.68647) to currency data type. It returns a value 10.6865.
'Convert a Value(10.68647) to Currency Data Type Sub VBA_CCur_Function_Ex3() 'Variable declaration Dim iValue As Double Dim bResult As Currency iValue = 10.68647 bResult = CCur(iValue) MsgBox "The value(10.68647) in currency is : " & bResult, vbInformation, "VBA CCur Function" End Sub
Output: Here is the screen shot of the third example output.
Example 4: Convert a String(‘Example’) to Currency Data Type
Here is a simple example of the VBA CCur function. This below example converts an expression to currency data type. It returns an error. Because, we can’t convert string to currency data type.
'Convert a String('Example') to Currency Data Type Sub VBA_CCur_Function_Ex4() 'Variable declaration Dim iValue As String Dim bResult As Currency iValue = "Example" bResult = CCur(iValue) MsgBox Err.Description, vbInformation, "VBA CCur Function" End Sub
Output: Here is the screen shot of the fourth example output.
Instructions to Run VBA Macro Code or Procedure:
You can refer the following link for the step by step instructions.
Instructions to run VBA Macro Code
Other Useful Resources:
Click on the following links of the useful resources. These helps to learn and gain more knowledge.
VBA Tutorial VBA Functions List VBA Arrays in Excel Blog
VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers
Excellent article! We are linking to this particularly great article on our site.
Keep up the great writing.