Microsoft Office Tutorials and References
In Depth Information
Chapter 13: Introducing VBA
If you know that Sheet1 is the active sheet, you can simplify the reference even
Objects have properties .
A property can be thought of as a setting for an object. For example, a Range
object has properties such as Value and Name. A Chart object has properties such
as HasTitle and ChartType. You can use VBA to determine object properties and
also to change them.
You refer to properties by combining the object with the property, separated by
For example, you can refer to the value in cell A1 on Sheet1 as
You can assign values to VBA variables.
Think of a variable as a name that you can use to store a particular value.
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
You can also assign a variable’s value to a cell.
To assign a variable called Interest to cell A1 on Sheet1, use the following VBA
Worksheets(“Sheet1”).Range(“A1”).Value = Interest
Objects have methods .
A method is an action that is performed with the object. For example, one of the
methods for a Range object is ClearContents. This method clears the contents of
You specify methods by combining the object with the method, separated by a
For example, to clear the contents of cell A1 on the active worksheet, use this:
VBA also includes all the constructs of modern programming languages,
including arrays, looping, and so on.
Believe it or not, this summary pretty much describes VBA. Now it’s just a matter
of learning some details.