VBA Integer Data Type in Excel 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 contains 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.
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.
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
Here is an example on the Data Type Integer 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
You can convert an expression to VBA data type Integer using VBA CInt function. Click on the following link to learn about CInt function and complete tutorial and examples.
Other VBA Data Types
Please click on the following link to read about all other data types.
You can refer the following link for the step by step instructions.
Click on the following links of the useful resources. These helps to learn and gain more knowledge.