Applies To
Application Object, Range Object, Worksheet Object.
Description
Accessor. Returns a Range object that represents a single row (Syntax 1) or a collection of rows (Syntax 2).
Syntax 1
object.Rows(index)
Syntax 2
object.Rows
object
Optional for Application, required for Range and Worksheet. The object that contains the rows. If you specify the Application object (or omit the object qualifier), this method applies to the active sheet in the active workbook. If the active sheet is not a worksheet, this method fails.
index
Required for Syntax 1. The name or number of the row.
Remarks
When applied to a Range object that is a multiple selection, this method returns rows from the first area of the range only. For example, if the Range object is a multiple selection with two areas, A1:B2 and C3:D4, Selection.Rows.Count returns 2, not 4. To use this method on a range that may contain a multiple selection, test Areas.Count to determine if the range is a multiple selection, and if it is, then loop over each area in the range; see the second example.
See Also
Columns Method, Range Method.
Example
This example deletes row three on Sheet1.
Worksheets("Sheet1").Rows(3).Delete
This example displays the number of rows in the selection on Sheet1. If more than one area is selected, the example loops through every area.
Worksheets("Sheet1").Activate areaCount = Selection.Areas.Count If areaCount <= 1 Then MsgBox "The selection contains " & _ Selection.Rows.Count & " rows." Else i = 1 For Each a In Selection.Areas MsgBox "Area " & i & " of the selection contains " & _ a.Rows.Count & " rows." i = i + 1 Next a End If