【发布时间】:2017-08-04 12:38:48
【问题描述】:
在另一篇文章中,我获得了以下 VBA 代码,用于附加到“刷新”按钮以刷新 Pivot 数据:
Option Explicit
Sub Button5_Click()
Dim PvtTbl As PivotTable
Dim PvtCache As PivotCache
Dim PvtDataRng As Range
' Set/Update Pivot Data Range
Set PvtDataRng = Worksheets("PivotDataSheet").Range("A1:E100") ' <-- just an example
' Create/Update Pivot Cache
Set PvtCache = ActiveWorkbook.PivotCaches.Add(xlDatabase, PvtDataRng)
' Set the Pivot Table (already created, otherwise need to create it)
Set PvtTbl = Worksheets("DD").PivotTables("test")
' refresh the Pivot Table with the latest Pivot Cache
With PvtTbl
.ChangePivotCache PvtCache
.RefreshTable
End With
End Sub
如何修改此代码以同时刷新同一工作表中的第二个数据透视?让我们将此第二个枢轴称为“test2”,它也在 DD 工作表中。
谢谢, 凯夫博
【问题讨论】:
-
只需使用其他数据透视表名称重复您获得的代码的步骤...
-
第二个名为“test2”的数据透视表是否与第一个数据透视表具有相同的数据源?
-
两个数据透视表是否基于相同的数据源?
-
是的,他们使用相同的数据源。不会添加此代码的副本会覆盖 Set PvtTbl =? 的定义