Microsoft Office Tutorials and References
In Depth Information
Variables are declared within a procedure by using the Dim , or dimension, statement. The
most common usage of the Dim statement is
Dim varname as type
This statement explicitly declares a variable named varname as a variable of type . Multiple
variables can be declared on one line by separating them with a comma, like this:
Dim varname1 as type , varname2 as type , ...
Defining Data Types
When variables are declared, they should be declared as a specific data type. This data type
determines the values that can be stored within the variable and how much memory is required
to store the value. VBA provides different data types to handle numbers, strings, dates and
times, Boolean values, and objects. You can even declare your own data type when needed.
The majority of the data types available in VBA are numeric types, each of which handles a
different range of values with varying amounts of precision. The numeric data types along
with their specifications are listed in Table 4-7.
Table 4-7. Numeric Data Types
0 to 255
A signed, fixed-point
number with up to 15
digits to the left of the
decimal and 4 digits to
the right; used for
financial or other
calculations requiring a
high degree of precision
Can’t be directly
with no decimal point and +/-
declared in VBA;
requires the use of a
28 digits behind the decimal point.
Variant data type