我试图在过滤器/切片器发生变化时运行宏,但要在数据透视表刷新/重新计算之前。
我想出了一个变通的办法,但是如果有一种方法可以在数据透视表更新被请求时触发一个宏,我可以写一个更简单的代码。我知道有一个事件可以在数据透视表完成刷新后使用。
我尝试了以下方法。它们都不起作用,在数据透视表刷新期间也不会触发。
PivotTableBeforeAllocateChanges
PivotTableBeforeCommitChanges
PivotTableBeforeDiscardChanges
我确实在工作表代码中有这些,而不是在模块中。我使用了微软的示例代码。
我想在pivot刷新之前运行的代码:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
CalcCol = Sheets("References").Range("B1")
Columns(CalcCol).Delete
End Sub
1条答案
按热度按时间jei2mxaa1#
您可以在Worksheet_Change事件中捕获它,并查看“目标”中是否包含数据透视表更改。如果有更改-您可以撤消它-然后运行代码并重新执行它?
我使用这种方法来捕获对切片器的更改,这样我就可以给人们带来很好的切片器体验,而不是控件或电子表格下拉列表(当我必须单击其中一个时,我会呻吟!)
我的代码如下。