VBA CCur Function

VBA CCur Function

Objective of VBA CCur Function:


VBA CCur Function is categorized 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 can be used 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.

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.
VBA CCur Function

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.
VBA CCur Function

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.
VBA CCur Function

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.
VBA CCur Function

Instructions to use Macro Codes

Here are the step by step instructions to use the CCur Function in Excel VBA.

  • Open an Excel workbook.
  • Press Alt+F11 to open VBA Editor window.
  • Go to Insert menu and click on module from the available options.
  • Copy above specified macros to the VBA editor.
  • Select any procedure from above codes and click on ‘Run’ command or use Keyboard shortcut ‘F5’.

List of VBA Functions:

Please click on below link to go back to see all List of VBA Functions.

VBA Data Type Conversion Functions List of VBA Functions

Leave a Comment

Your email address will not be published. Required fields are marked *