Decimal Data Type in Excel VBA

VBA Decimal Data Type in Excel

Decimal Data Type in Excel VBA explained with syntax and examples.Decimal VBA Data Type in Excel VBA explained with syntax and examples. We use the Decimal VBA data type to store integer numbers scaled by a variable power of 10. The default value is 0.

The Decimal VBA data type contains range of values +/-79,228,162,514,264,337,593,543,950,335 with no decimal point;+/-7.9228162514264337593543950335 with 28 decimal places to the right of the decimal. The smallest nonzero value is +/-0.0000000000000000000000000001. It is one of the VBA data type and Default value of Decimal is ‘Empty’. Long occupies 14 bytes(112 bits) in memory and supports 29 significant figures. Long VBA data type has literal type character ‘D’ and identifier type character ‘@’ to Decimal.

It performs slowest performance compares to other data types. A variable can’t be declared as a decimal, we need to declare as a single or double depending on requirement.

Decimal VBA Data type Syntax in Excel

Let us see Data Type Decimal Syntax in Excel VBA.

Dim VariableName as Decimal

Where VariableName represents the name of the variable.
and Decimal represents the type of data.

Example on the Decimal VBA Data Type in Excel

Here is an example on the Decimal VBA Data Type in Excel.

Sub VBAF1_Decimal_DataType()
    
    'Integer Variable Declaration
    Dim iValue As Variant
    
    'Assign value to integer variable
    iValue = CDec(10000000000.1234)
    
    MsgBox "Type Name of Value(10000000000.1234) is : " & TypeName(iValue), vbInformation, "VBAF1"
     
End Sub

Here is the output screenshot of above macro.

Decimal VBA Data Type

Convert an Expression to Decimal VBA Data Type in Excel

You can convert an expression to Decimal VBA data type using VBA CDec function. Click on the following link to learn about CDec function and complete tutorial and examples.

VBA CDec Function

VBA Data Types

Also read about all other data types.

VBA Data Types

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 VBA Text Files VBA Tables

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers Blog

1 thought on “Decimal Data Type in Excel VBA”

Leave a Comment