Datasheet

20
Part I: Introducing VBA
You can assign values to variables. A variable is a named element that
stores information. You can use variables in your VBA code to store
such things as values, text, or property settings. To assign the value
in cell A1 on Sheet1 to a variable called Interest, use the following VBA
statement:
Interest = Worksheets(“Sheet1”).Range(“A1”).Value
Objects have methods. A method is an action Excel performs with
an object. For example, one of the methods for a Range object is
ClearContents. This aptly named method clears the contents of the
range.
You specify a method by combining the object with the method, sepa-
rated by a dot. For example, the following statement clears the contents
of cell A1:
Worksheets(“Sheet1”).Range(“A1”).ClearContents
VBA includes all the constructs of modern programming languages,
including arrays and looping. In other words, if you’re willing to spend
a little time mastering the ropes, you can write code that does some
incredible things.
Believe it or not, the preceding list pretty much describes VBA in a nutshell.
Now you just have to find out the details. That’s why this book has more
pages.
An Excursion into Versions
If you plan to develop VBA macros, you should have some understanding
of Excel’s history. I know you weren’t expecting a history lesson when you
picked up this book, but bear with me. This is important stuff that might
make you a hit at the next nerd party.
Here are all the major Excel for Windows versions that have seen the light of
day, along with a few words about how they handle macros:
Excel 2: The original version of Excel for Windows was called Version
2 (rather than 1) so that it would correspond to the Macintosh version.
Excel 2 first appeared in 1987, but nobody uses it anymore, so you can
pretty much forget that it ever existed.
Excel 3: Released in late 1990, this version features the XLM macro lan-
guage. Nobody uses this version either.
05_503690-ch01.indd 2005_503690-ch01.indd 20 4/12/10 11:22 PM4/12/10 11:22 PM