Forum Discussion

chancelin's avatar
chancelin
Copper Contributor
Nov 28, 2018

Use the Offset Property to Refer to a Range

Offset enables you to manipulate a cell based off the location of the active cell. In this way, you do not need to know the address of a cell.

The syntax for the Offset property is as follows:

Range.Offset(RowOffset, ColumnOffset)

The syntax to affect cell F5 from cell A1 is

Range("A1").Offset(RowOffset:=4, ColumnOffset:=5)

Or, shorter yet, write this:

Range("A1").Offset(4,5)

The count of the rows and columns starts at A1 but does not include A1.

But what if you need to go over only a row or a column, but not both? You don’t have to enter both the row and column parameter. If you need to refer to a cell one column over, use one of these lines:

Range("A1").Offset(ColumnOffset:=1)

Range("A1").Offset(,1)

Both lines mean the same, so the choice is yours. Referring to a cell one row up is similar:

Range("B2").Offset(RowOffset:=-1)

Range("B2").Offset(-1)

Once again, you can choose which one to use. It is a matter of readability of the code.

No RepliesBe the first to reply

Resources