Offset Property

Microsoft Office Web Components Visual Basic

expression.Offset(RowOffset, ColumnOffset)

expression    Required. An expression that returns a Range object.

RowOffset   Optional Variant. The number of rows (positive, negative, or 0 (zero)) by which the range is to be offset. Positive values are offset downward, and negative values are offset upward. The default value is 0.

ColumnOffset   Optional Variant. The number of columns (positive, negative, or 0 (zero)) by which the range is to be offset. Positive values are offset to the right, and negative values are offset to the left. The default value is 0.

Example

This example sets the font for the contents of the cell that is one column to the right of the active cell.

Spreadsheet1.ActiveCell.Offset(0, 1).Font.Bold = True
		

This example loops through the contiguous values in column A in the active sheet of Spreadsheet1 and deletes any rows that contain odd-numbered values.

Sub Delete_Odd_Values()

    Spreadsheet1.ActiveSheet.Range("A1").Select

    ' Loop until an empty cell is selected.
    Do Until IsEmpty(Spreadsheet1.ActiveCell)

        ' If the active cell contains an odd number.
        If Spreadsheet1.ActiveCell.Value Mod 2 = 1 Then
            ' Delete the row.
            Spreadsheet1.ActiveCell.EntireRow.Delete
        Else
            ' Select the next cell.
            Spreadsheet1.ActiveCell.Offset(1, 0).Select
        End If
    Loop
End Sub