Microsoft Office Tutorials and References
In Depth Information
Declaring variables
T ABLE 14-1 VBA’S DATA TYPES (Continued)
Data Type
Bytes Used
Range of Values
14 bytes
with no decimal point;
with 28 places to the right of the decimal
8 bytes
January 1, 0100 to December 31, 9999
4 bytes
Any object reference
String (variable-length)
10 bytes +
0 to approximately 2 billion
string length
String (fixed-length)
Length of string
1 to approximately 65,400
Variant (with numbers)
16 bytes
Any numeric value up to the range of a
double data type
22 bytes +
0 to approximately 2 billion
(with characters)
string length
Declaring variables
Before you use a variable in a procedure, you may want to declare it. Declaring a
variable tells VBA its name and data type. You declare a variable by using the Dim
keyword. For example, the following statement declares a variable named Count to
be an integer.
Dim Count As Integer
You also can declare several variables with a single Dim statement. For example:
Dim x As Integer, UserName As String, Rate As Double
If you don’t declare the data type for a variable that you use, VBA uses the
default data type, variant . Data stored as a variant acts like a chameleon: It
changes type depending on what you do with it.
Introducing object variables
An object variable is a variable that represents an entire object, such as a range or
a chart. Object variables, as with normal variables, are declared with a Dim
statement. For example:
Search JabSto ::

Custom Search