The Integer, Long, and Byte Data TypesThis content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Three data types in Microsoft® Visual Basic® for Applications (VBA) can represent integers, or whole numbers: the Integer, Long, and Byte data types. Of these, the Integer and Long types are the ones you are most likely to use regularly.
The Integer and Long data types can both hold positive or negative values. The difference between them is their size: Integer variables can hold values between -32,768 and 32,767, while Long variables can range from -2,147,483,648 to 2,147,483,647. Traditionally, VBA programmers have used integers to hold small numbers, because they required less memory. In recent versions, however, VBA converts all integer values to type Long, even if they are declared as type Integer. Therefore, there is no longer a performance advantage to using Integer variables; in fact, Long variables might be slightly faster because VBA does not have to convert them.
The Byte data type can hold positive values from 0 to 255. A Byte variable requires only a single byte of memory, so it is very efficient. You can use a Byte variable to hold an Integer value if you know that value will never be greater than 255. However, the Byte data type is typically used for working with strings. For some string operations, converting the string to an array of bytes can significantly enhance performance.
Working with Numbers | The Boolean Data Type | The Floating-Point Data Types | The Currency and Decimal Data Types | Conversion, Rounding, and Truncation | Formatting Numeric Values | Using the Mod Operator | Performing Calculations on Numeric Arrays