A variable has a unique name by which it can be referenced in the code. In VBA, the following rules apply to variable names:
- They must begin with a letter.
- They can only contain letters, numbers, and a few special characters (for example, the underscore _).
- They should not include German umlauts (ä, ö, ü) or the sharp s (ß).
- Within a given scope, no two variables may share the same name (see section 5.1, « Scopes »).
Valid examples of variable names are: Temperature, Summe_Werte, or X12.
Invalid examples include: 5Tage (because it starts with a digit) or Tag#12 (because it contains an invalid character #).
Variables receive their values through assignment using the equal sign =. It is advisable to assign a value to a variable before its first use, for example:
Temperature = 25
Assigning values early makes programs clearer, easier to read, and less prone to errors.