尝试同步来自两个不同数据源的两个切片器。我将使用第一个切片器来更改多个图表的视图。来自不同数据源的字段是相同的,其中的值相同。我是VBA的新手,所以只需学习一下。
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
'Declaring variables
Dim sc1 As SlicerCache
Dim sc2 As SlicerCache
Dim SI1 As SlicerItem
'These names come from Slicer Settings dialog box
Set sc1 = ThisWorkbook.SlicerCaches("Slicer_Customer_Region1")
Set sc2 = ThisWorkbook.SlicerCaches("Slicer_Customer_Region2")
'make the macro faster
Application.EnableEvents = False
Application.ScreenUpdating = False
'Clearing filters to mirror sc1
sc2.ClearManualFilter
'Getting error here
For Each SI1 In sc1.SlicerItems
sc2.SlicerItems(SI1.Customer_Region).Selected = SI1.Selected
Next SI1
'make the macro faster
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub