我在工作表2中有一个数据透视表。每次更改工作表1单元格D1中的值时,数据透视表过滤器将自动更改。但是,当我返回到工作表2并单击屏幕上的任意位置时,该表仅刷新。如何让它自动更改?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Set worksheet and cell
Set pt = Worksheets("Sheet2").PivotTables("PivotTable1")
Set Field = pt.PivotFields("Sum1")
NewCat = Worksheets("Sheet1").Range("D1").Value
'Update and refresh
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.Update
End With
End Sub
注意:我也尝试过pt.Refresh和pt.RefreshTable