Select Method | Range.Offset | Selection Property | Selection.Offset | Interior.Color
Select Method
The Select Method presented here is an important method of the Range Object.
Sub SelectDemo()
Range("A1:B3").Select
End Sub
Result:
The Range.Select Method selects the cells in your range.
Range.Offset Property
The Offset Property adjusts your position based on the initial Range you define.
Sub SelectDemo()
Range("A1:B3") = 3
Range("A1:B3").Offset(1, 2).Select
End Sub
Result:
The Offset Property accepts two arguments: a row and a column. In the example above, the range is offset by 1 row and 2 columns before being selected.
Selection Property
The Selection Property refers to the currently selected range or item and can be used to manipulate values. As a general rule of thumb, most things you can perform with the Range Object, you can also perform with Selection. Keep in mind that selecting cells individually in your VBA macros will slow your code down. I recommend using Application.ScreenUpdating=False if you’re selecting cells.
Selection.Offset Property
Sub SelectionDemo()
Range("A1").Select
Selection.Offset(1, 0).Select
End Sub
Result:
Offsetting the currently selected cell by 1 row is quite useful inside long VBA loops. If you’re a loyal follower of my VBA Tutorials Blog, I’m sure you’ve seen me do this. The Selection property is rarely needed, but I’ll use it on occasion inside large loops since the Integer Data Type is limited to integers less than 32,767.
Interior.Color Property
Sub SelectionDemo()
Range("A1").Select
Selection.Interior.Color = vbYellow
End Sub
Result:
The Color Property, a property of the Interior Object, is used to change the cell color. Remember, you can use Selection.Clear
to clear the formatting.
In this lesson, you learned about the Select Method of the Range Object and about the Selection Property. You learned how to offset your current selection, which is useful inside long VBA loops, and you learned that Selection shares many Properties and Methods with the Range Object.
If you really want to learn VBA, grab a copy of our Ultimate VBA Training Bundle before reading our next tutorial. We specifically created these cheat sheets to help you get the most out of our upcoming lessons. Together, the set has over 200 practical tips covering the 125 most important topics in Excel VBA. We also stuffed it with 140 helpful macro examples.