Moving around the Worksheet in VBA for Excel
Offset in VBA for Excel
The Offset property is the one that you will use the most with Range to move around the sheet. It is the very important property that allows you to move right, left, up and down and to extend the size of the selection.
To move one cell down (from B2 to B3): Range("B2").Offset(1,0).Select
As you notice the first argument between the parentheses for Offset is the number of rows and the second one is the number of columns.
Knowing this you will expect an error message if you write:
If you'd try to execute any of the two lines of code above you would see this:
Here is a piece of code that you will use very frequently if you want to select one cell and 3 more down:
If you want to select the cell that is already selected plus 3 mor down the code is:
Often you will get the following error message when you try to write such sentences:
and it is because you are forgetting the second parenthesis before Select.
For advanced users: With Offset you can also replace the numbers within the parenthesis with a number that you have stored in another cell or with a number that is in a variable: