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
more:
Range(“”A1””)
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
a period.
For example, you can refer to the value in cell A1 on Sheet1 as
Worksheets(“”Sheet1”).Range(“”A1”).Value
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
statement:
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
the range.
You specify methods by combining the object with the method, separated by a
period.
For example, to clear the contents of cell A1 on the active worksheet, use this:
Range(“A1”).ClearContents
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.
Search JabSto ::




Custom Search