VBA Notes
Lesson 4. VBA Data Types
VBA Data Types
The computer cannot differentiate between the number (1,2,3.......) and string (a,b,c..........) to make this differentiation, we use the Data Types.
The Data Type, you assign to a variable will be dependent on the type of data, you want that variable to hold.
In VBA, there are many data types. We divide the data types into two main categories, namely numeric and non numeric data types
Below is the table that shows all the available data types you can use in VBA Excel.
Numeric Data Types
Non-Numeric Data Types
When you specify the data type of a variable in code, it tells VBA to how to store the variable, and how much space has to allocate for it.
For Example: If you need to use a variable is meant to hold the month number, You can use the Byte data type (which accommodate values from 0 to 255). Since the month number is not going to be above 12, this will work fine and also reserve less memory for this variable.
If you need a variable to store the row numbers in Excel, You need to use a data type that can accommodate a number up to 1048576. So it's good to use the Long data Type.
Post a Comment
0 Comments