Class ListRows (Excel VBA)

A collection of all the ListRow objects in the specified ListObject object. To use a ListRows class variable it first needs to be instantiated, for example


Dim lrs as ListRows
Set lrs = ActiveCell.ListObject.ListRows

For Each

Here is an example of processing the ListRows items in a collection.


Dim lstrw As ListRow
For Each lstrw In ActiveCell.ListObject.ListRows
	
Next lstrw

Add

Adds a new row to the table represented by the specified ListObject.

If Position is not specified, a new bottom row is added. If AlwaysInsert is not specified, the cells below the table will be shifted down one row (same as specifying True).

Add (Position, AlwaysInsert)


Dim lstrw As ListRow
Set lstrw = ActiveCell.ListObject.ListRows.Add

Arguments

Optional arguments

The following arguments are optional

Position (Integer) - Specifies the relative position of the new row.

AlwaysInsert (Boolean) - Specifies whether to always shift data in cells below the last row of the table when the new row is inserted, regardless if the row below the table is empty. If True, the cells below the table will be shifted down one row. If False, if the row below the table is empty, the table will expand to occupy that row without shifting cells below it, but if the row below the table contains data, those cells will be shifted down when the new row is inserted.

Count

Returns an Integer value that represents the number of objects in the collection.


Dim lngCount As Long
lngCount = ActiveCell.ListObject.ListRows.Count

Item

Returns a single object from a collection.

Item (Index)

Index: The name or index number of the object.


Dim lstrwItem As ListRow
Set lstrwItem = ActiveCell.ListObject.ListRows(Index:=1)