Offset Property

The Offset property is used to return a range that is offset from a given range by a certain number of rows and/or columns. The syntax is:

RangeObject.Offset(RowOffset, ColumnOffset)

where RowOffset is the number of rows and ColumnOffset is the number of columns by which the range is to be offset. Note that both of these parameters are optional with default value 0, and both can be either positive, negative, or 0.

For instance, the following code searches the first 100 cells to the immediate right of cell D2 for an empty cell (if you tire of the message boxes, simply press Ctrl-Break to halt macro execution):

Dim rng As Range Dim i As Integer Set rng = Range("D2") For i = 1 To 100

MsgBox "Found empty cell at offset " & i & " from cell D2" End If Next

0 0

Post a comment