Microsoft Office Tutorials and References
In Depth Information
19.2.4 Offset Property
19.2.4 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
If rng.Offset(0, i).Value = "" Then
MsgBox "Found empty cell at offset " & i & " from cell D2"
End If
Next
19.3 Additional Members of the Range Object
Let us now take a quick look at some additional members of the Range object. (Please refer to
Table 19-1 for an indication of which members are discussed in this section.)
19.3.1 Activate Method
The Activate method will activate (or select) the range to which it is applied. The Activate method
applies to a variety of other objects besides the Range object, such as the Window object, the
Worksheet object, and the Workbook object.
19.3.2 AddComment Method
This method adds a Comment object (i.e., a comment) to the single-cell range. Its syntax is:
RangeObject .AddComment( Text )
where Text is the text of the comment. For instance, the code:
Dim rng As Range
Dim c As Comment
Set rng = Range("B2")
Set c = rng.AddComment("This is a comment")
adds a comment to cell B2 with the text "This is a comment." Note that if RangeObject consists
of more than a single cell, a runtime error results.
19.3.3 Address Property (Read-Only String)
 
Search JabSto ::




Custom Search