这应该有助于回答您的问题。
Sub TableStuff()
Dim lo As Excel.ListObject
Dim loRow As Excel.ListRow
Dim i As Long
Set lo = ActiveSheet.ListObjects(1)
With lo
'this is the address of the whole table
Debug.Print .Range.Address
For i = 1 To 10
Set loRow = .ListRows.Add(i)
loRow.Range.Cells(1).Value = "test" & i
Next i
Debug.Print .Range.Address
'address of data rows
Debug.Print .DataBodyRange.Address
End With
End Sub
我的博客上有两篇关于表格的文章。最近的一篇文章也可能提供一些见解。
编辑:根据下面的评论并编辑到 OP:
这假定 Activesheet 上有两个表,tblSource 和 tblIncome。它将源表过滤到收入,复制可见行并将它们插入到 tblIncome 的末尾。最后,它删除源行(除一个之外的所有行)。
您需要添加一个循环以使其适用于其他两个类别:
Sub MoveTableStuff()
Dim loSource As Excel.ListObject
Dim loTarget As Excel.ListObject
Dim SourceDataRowsCount As Long
Dim TargetDataRowsCount As Long
Set loSource = ActiveSheet.ListObjects("tblSource")
Set loTarget = ActiveSheet.ListObjects("tblIncome")
With loSource
.Range.AutoFilter Field:=1, Criteria1:="income"
SourceDataRowsCount = .ListColumns(1).DataBodyRange.SpecialCells(xlCellTypeVisible).Count
End With
With loTarget
TargetDataRowsCount = .DataBodyRange.Rows.Count
.Resize .Range.Resize(.Range.Rows.Count + SourceDataRowsCount, .Range.Columns.Count)
loSource.DataBodyRange.SpecialCells(xlCellTypeVisible).Copy
.DataBodyRange.Cells(TargetDataRowsCount + 1, 1).PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
End With
With loSource
.Range.AutoFilter
.DataBodyRange.Offset(1).Resize(.DataBodyRange.Rows.Count - 1, .DataBodyRange.Columns.Count).Rows.Delete
End With
End Sub