Skip to main content

Worksheet.Rows property

Table of contents
  1. Syntax
  2. Remarks
  3. Example

Returns a Range object that represents all the rows on the specified worksheet.

Syntax

expression.Rows

expression A variable that represents a Worksheet object.

Remarks

Using the 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, use the Item property or equivalently include an index in parentheses. For example, both Rows(1) and Rows.Item(1) return the first row of the active sheet.

Example

This example deletes row three on Sheet1.

Worksheets("Sheet1").Rows(3).Delete

This example deletes all rows on worksheet one where the value of cell one in the row is the same as the value of cell one in the previous row.

For Each rw In Worksheets(1).Rows
    this = rw.Cells(1, 1).Value
    If this = last Then rw.Delete
    last = this
Next

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>