我需要帮助!
我有一个切片器,需要在其中选择客户代码列表-该列表将不断增长。 我有下面的代码,但是下面的代码行出现“ 1004”错误,我无法一生找出原因。
错误行: 设置SI = SC.SlicerItems 对于SC.VisibleSlicerItemsList
中的每个SI完整代码:
Option Explicit
Sub filterSlicers()
Dim i As Long
Dim SI As SlicerItems
Dim SC As SlicerCache
Dim PvT As PivotTable
Dim C As Range
Dim Cell As Range
Dim 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:A14")
Set DictFilter = New Scripting.Dictionary
For Each Cell In C
DictFilter.Add Cell.Value, 1
Next Cell
Set SC = ThisWorkbook.SlicerCaches("Slicer_Customer_Code")
SC.ClearAllFilters
Set SC = ThisWorkbook.SlicerCaches("Slicer_Customer_Code")
SC.ClearAllFilters
Set SI = SC.SlicerItems
For Each SI In SC.VisibleSlicerItemsList
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
非常感谢您的任何反馈!