Class ListRow (Excel VBA)

The class ListRow represents a row in a table. The ListRow object is a member of the ListRows collection.

Item

To use a ListRow class variable it first needs to be instantiated, for example

Dim lstrw as ListRow
Set lstrw = ActiveCell.ListObject.ListRows(Index:=1)

The following procedures can be used to set variables of type ListRow: ListRows.Add and ListRows.Item.

For Each

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

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

Delete

Deletes the cells of the list row and shifts upward any remaining cells below the deleted row. You can delete rows in the list even when the list is linked to a SharePoint site. The list on the SharePoint site will not be updated, however, until you synchronize your changes.

ActiveCell.ListObject.ListRows(1).Delete

Index

Returns a Long value that represents the index number of the ListRow object within the ListRows collection.

Dim lngIndex As Long
lngIndex = ActiveCell.ListObject.ListRows(1).Index

Range

Returns a Range object that represents the range to which the specified list object in the list applies.

Dim rngRange As Range
Set rngRange = ActiveCell.ListObject.ListRows(1).Range

ListRows.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 - Specifies the relative position of the new row

AlwaysInsert - 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

ListRows.Count

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

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

ListRows.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)