UNDERSTANDING VARIABLES
A variable is a named storage location in the computer's main memory.
VBA has a few rules regarding variable names:
-
Letters, numbers and some punctuation characters can be used.
-
Spaces and periods are not allowed.
-
VBA does not distinguish between upper and lower case letters.
-
The following characters are not allowed: #, $, %, &, or !.
-
Variable names cannot be longer than 254 characters.
VBA has reserved words that should not be used for variable names or procedure names:
- VBA language words such as Sub, With, and For.
- Built-in VBA function names such as Ucase and Sqr.
Variable names should be as descriptive as possible.
To make variable names more readable, mixed cases or underscores are used to make compound-word variable names.
Examples of valid variable names: InterestRate, StudentName, StudentID, Is_Angry, Exam1Score.
Examples of invalid variable names: Interest Rate, InterestRate$, Interest.Rate.