Worksheet.Rows property (Excel)
Returns a Range object that represents all the rows on the specified worksheet.
expression A variable that represents a Worksheet object.
Rows property without an object qualifier is equivalent to using
ActiveSheet.Rows. If the active document isn't a worksheet, the
Rows property fails.
To return a single row, include an index in parentheses. For example,
Rows(1) returns the first row.
This example deletes row three on Sheet1.
This example deletes rows in the current region on worksheet one where the value of cell one in the row is the same as the value in cell one in the previous row.
For Each rw In Worksheets(1).Cells(1, 1).CurrentRegion.Rows this = rw.Cells(1, 1).Value If this = last Then rw.Delete last = this Next
This example displays the number of rows in the selection on Sheet1. If more than one area is selected, the example loops through each 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
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.