Rows Collection

Rows Collection
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Table
Aa662054.parchild(en-us,office.10).gifRows
Aa662054.space(en-us,office.10).gifAa662054.parchild(en-us,office.10).gifRow

A collection of Row objects that represent the rows in a table.

Using the Rows collection

Use the Rows property of the Table object to return the Rows collection. The following example displays the number of Row objects in the Rows collection for the first table in the active document.

  Sub CountRows()
    MsgBox ActiveDocument.Pages(2).Shapes(1).Table.Rows.Count
End Sub

This example sets the fill for all even-numbered rows and clears the fill for all odd-numbered rows in the specified table. This example assumes the specified shape is a table and not another type of shape.

  Sub FillCellsByRow()
    Dim shpTable As Shape
    Dim rowTable As Row
    Dim celTable As Cell

    Set shpTable = ActiveDocument.Pages(2).Shapes(1)
    For Each rowTable In shpTable.Table.Rows
        For Each celTable In rowTable.Cells
            If celTable.Row Mod 2 = 0 Then
                celTable.Fill.ForeColor.RGB = RGB _
                    (Red:=180, Green:=180, Blue:=180)
            Else
                celTable.Fill.ForeColor.RGB = RGB _
                    (Red:=255, Green:=255, Blue:=255)
            End If
        Next celTable
    Next rowTable

End Sub

Use Rows(index), where index is the index number, to return a single Row object. The index number represents the position of the row in the Rows collection (counting from left to right). The following example selects the third row in the specified table.

  Sub SelectRows()
    ActiveDocument.Pages(2).Shapes(1).Table.Rows(3).Cells.Select
End Sub