VBA Integer Data Type in Excel

Integer Data Type in Excel VBA

Integer Data Type in Excel VBA explained with syntax and examples. We use the integer VBA data type to store only integer whole numbers. The default value is 0. The integer VBA data type conatins range of values between -32,768 to 32,767. Integers cannot have decimal places. The integer number can be positive number, negative number or zero. It is most common frequently used VBA data type. It occupies 2 bytes(16 bits) in memory.

Integer VBA Data Type Syntax in Excel

Let us see the Integer VBA Data Type Syntax in Excel.

Dim VariableName as Integer

Where VariableName represents the name of the variable.
and Integer represents the type of data which contains whole number.

Example on the Integer VBA Data Type in Excel

Here is an example on the Integer Data Type in Excel VBA. In the below example ‘iValue’ is a integer variable and it contains a positive value 800.

Sub VBAF1_Integer_DataType()
    
    'Integer Variable Declaration
    Dim iValue As Integer
    
    'Assign value to integer variable
    iValue = 800
    
End Sub

Example on the Integer VBA Data Type in Excel

Here is an example on the Integer Data Type in Excel VBA.In the below example ‘iValue’ is a integer variable and it contains a negative value – 800.

Sub VBAF1_Integer_DataType()
    
    'Integer Variable Declaration
    Dim iValue As Integer
    
    'Assign value to integer variable
    iValue = -800
    
End Sub

Convert an Expression to Integer VBA Data Type in Excel VBA

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

VBA CInt Function

Other VBA Data Types

Please click on the following link to read about all other data types.

VBA Data Types

Leave a Comment

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