清除 VBA 中多个表的数据
Clearing Data from Multiple Tables in VBA
我在名为 "Builder" 的 sheet 上有 20 个 table 系列,每个都有自己的名字。我想要做的是创建一个变量,该变量仅隔离我告诉它的 19 个 table,以便我在它们上创建一个 clear content
过程。剩下的 1 个 table 需要保持不变,因为这个 table 是其他 19 个的概述。我发现下面删除了 1 table 的行,但我需要将它扩展到 运行多个进程。
Sub Macro3()
With Sheets(Builder").ListObjects("P6WC_00002")
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.Delete
End If
End With
End Sub
table 名字的其他几个例子是:D86-03116
、D87-03215
、F08-00025
提前致谢
使用 For Each
循环和排除检查:
Dim TableToCheck AS ListObject
For Each TableToCheck In ThisWorkbook.Worksheets("Builder").ListObjects
If TableToCheck.Name <> "P6WC_00000" Then 'Name of Table you do NOT want to update
If Not (TableToCheck.DataBodyRange Is Nothing) Then TableToCheck.DataBodyRange.Delete
End If
Next TableToCheck
我在名为 "Builder" 的 sheet 上有 20 个 table 系列,每个都有自己的名字。我想要做的是创建一个变量,该变量仅隔离我告诉它的 19 个 table,以便我在它们上创建一个 clear content
过程。剩下的 1 个 table 需要保持不变,因为这个 table 是其他 19 个的概述。我发现下面删除了 1 table 的行,但我需要将它扩展到 运行多个进程。
Sub Macro3()
With Sheets(Builder").ListObjects("P6WC_00002")
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.Delete
End If
End With
End Sub
table 名字的其他几个例子是:D86-03116
、D87-03215
、F08-00025
提前致谢
使用 For Each
循环和排除检查:
Dim TableToCheck AS ListObject
For Each TableToCheck In ThisWorkbook.Worksheets("Builder").ListObjects
If TableToCheck.Name <> "P6WC_00000" Then 'Name of Table you do NOT want to update
If Not (TableToCheck.DataBodyRange Is Nothing) Then TableToCheck.DataBodyRange.Delete
End If
Next TableToCheck