Microsoft Office Tutorials and References
In Depth Information
Variables, Data Types, and Constants
h Use comments to describe workarounds that you develop to overcome Excel bugs or
h Write comments while you code rather than after.
In some cases, you may want to test a procedure without including a particular
instruction or group of instructions. Instead of deleting the instruction, simply turn it into a
comment by inserting an apostrophe at the beginning. VBA then ignores the
instruction(s) when the routine is executed. To convert the comment back to an
instruction, just delete the apostrophe.
The Visual Basic Editor (VBE) Edit toolbar contains two very useful buttons. (The Edit
toolbar isn’t displayed by default. To display this toolbar, choose
View➜Toolbars➜Edit.) Select a group of instructions and then click the Comment
Block button to convert the instructions to comments. The Uncomment Block button
converts a group of comments back to instructions.
Variables, Data Types, and Constants
VBA’s main purpose in life is to manipulate data. Some data resides in objects, such as worksheet
ranges. Other data is stored in variables that you create.
A variable is simply a named storage location in your computer’s memory. Variables can
accommodate a wide variety of data types — from simple Boolean values ( True or False ) to large,
double-precision values (see the following section). You assign a value to a variable by using the
equal sign operator (more about this process in the upcoming section, “Assignment
You make your life easier if you get into the habit of making your variable names as descriptive
as possible. VBA does, however, have a few rules regarding variable names:
h You can use alphabetic characters, numbers, and some punctuation characters, but the
first character must be alphabetic.
h VBA doesn’t distinguish between case. To make variable names more readable,
programmers often use mixed case (for example, InterestRate rather than interestrate ).
h You can’t use spaces or periods. To make variable names more readable, programmers
often use the underscore character ( Interest_Rate ).
h You can’t embed special type declaration characters ( # , $ , % , & , or ! ) in a variable name.
h Variable names can be as long as 254 characters — but using such long variable names
isn’t recommended.
Search JabSto ::

Custom Search