MrAutomation
New Member
- Joined
- Jun 18, 2017
- Messages
- 16
Duplicated at Stack Overflow, but no response.
I have a workbook with two pivot table that have the exact same slicers. I'm using a VBA script to synchronize the two slicers. I've named them the same with one as "Slicer_xxxx_Master" and the other as "Slicer_xxxx_Slave".
The code below works fine, except on slicers with lots of options. Since it sets the slices one by one, it re-filters the pivot table over and over again until all the required slices are set.
Is there a method to collect all the slice item values into an array and then set the Slave slicer values all at once?
I have a workbook with two pivot table that have the exact same slicers. I'm using a VBA script to synchronize the two slicers. I've named them the same with one as "Slicer_xxxx_Master" and the other as "Slicer_xxxx_Slave".
The code below works fine, except on slicers with lots of options. Since it sets the slices one by one, it re-filters the pivot table over and over again until all the required slices are set.
Is there a method to collect all the slice item values into an array and then set the Slave slicer values all at once?
Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Application.ScreenUpdating = False
Dim sC As SlicerCache
Dim sC_Slave As SlicerCache
Dim SL As SlicerCacheLevel
Dim sI As SlicerItem
Dim sI_Slave As SlicerItem
For Each sC In ActiveWorkbook.SlicerCaches
If InStr(1, sC.Name, "Master") Then
Set sC_Slave = ThisWorkbook.SlicerCaches(Replace(sC.Name, "Master", "Slave"))
For Each sI In sC.SlicerItems
If sI.Name <> ("(blank)") Then
Set sI_Slave = sC_Slave.SlicerItems(sI.Name)
If sI_Slave.Selected <> sI.Selected Then
sI_Slave.Selected = sI.Selected
End If
End If
Next
End If
Next
Application.ScreenUpdating = True
End Sub