Microsoft Office Tutorials and References
In Depth Information
Things to Know about Objects
ActiveCell.FormulaR1C1 = “3”
ActiveCell.Offset(-2, 0).Range(“A1”).Select
End Sub
Notice that the macro recorder uses the FormulaR1C1 property. Normally, you want to use the
Value property to enter a value into a cell. However, using FormulaR1C1 or even Formula
produces the same result.
Also notice that the generated code references cell A1 — a cell that was even involved in the
macro. This notation is a quirk in the macro recording procedure that makes the code more
complex than necessary. You can delete all references to Range(“A1”) , and the macro still works
Sub Modified_Macro1()
ActiveCell.FormulaR1C1 = “1”
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = “2”
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = “3”
ActiveCell.Offset(-2, 0).Select
End Sub
In fact, here’s a much more efficient version of the macro (which I wrote myself) that doesn’t do
any selecting:
Sub Macro1()
ActiveCell = 1
ActiveCell.Offset(1, 0) = 2
ActiveCell.Offset(2, 0) = 3
End Sub
Things to Know about Objects
The preceding sections introduced you to objects (including collections), properties, and
methods. But I’ve barely scratched the surface.
Essential concepts to remember
In this section, I note some additional concepts that are essential for would-be VBA gurus. These
concepts become clearer when you work with VBA and read subsequent chapters:
Search JabSto ::

Custom Search