我有一个数据透视表,其中显示了满足特定条件的客户列表。 此外,我还有一串其他数据透视表连接到切片器。 我需要切片器自动过滤出现在第一个数据透视表上的客户代码。
我有以下内容-但是我收到“错误457-密钥已与此集合中的元素关联” 怎么了?
Option Explicit
Sub filterSlicers()
Dim i As Long, SI As SlicerItem, SC As SlicerCache, PvT As PivotTable, C As Range, Cell As Range, ws As Worksheet
Dim DictFilter As Scripting.Dictionary
For Each PvT In ThisWorkbook.Sheets("Sheet1").PivotTables
PvT.ManualUpdate = True
Next PvT
Set ws = ThisWorkbook.Sheets("Sheet1")
Set C = ws.Range("A12:A120")
Set DictFilter = New Scripting.Dictionary
For Each Cell In C
DictFilter.Add Cell.Value, 1
Next Cell
Set SC = ThisWorkbook.SlicerCaches("Customer_Code")
SC.ClearAllFilters
For Each SI In SC.VisibleSlicerItems
Set SI = SC.SlicerItems(SI.Name)
If DictFilter.Exists(SI.Name) Then
SI.Selected = True
Else
SI.Selected = False
End If
Next
For Each PvT In ThisWorkbook.Sheets("Sheet1").PivotTables
PvT.ManualUpdate = False
Next PvT
End Sub
谢谢