当源 Table 包含公式时,使用 VBA 自动刷新数据透视表 Table

Auto-Refresh Pivot Table with VBA, when Source Table contains Formulas

我的目标是 Pivot Table 在我对源数据进行更改时自动更新。 "normal" 论坛中讨论的代码(见下文)不起作用。

Private Sub Worksheet_Change(ByVal Target As Range)
Worksheets("Pivot").PivotTables("Test").PivotCache.Refresh
End Sub

我的设置如下:

我已经使用上述代码试过运气。如果我覆盖 table 中的公式,数据透视表会自动更新。这意味着代码适用于该场景。

但是:如果 table 中的数字因公式而发生变化(意味着选项卡 "Overview" 发生变化),我的数据透视表 Table 不会更新。

有人知道解决这个问题的方法吗?非常感谢!

我认为您必须在 "Constituents" 和 "Overview"

的两个工作表中添加 Worksheet_Change 函数