anamnesis111
New Member
- Joined
- Apr 6, 2018
- Messages
- 1
Hi, I have 4 data sources and 10 pivots so I created 4 slicers. To link the 4 slicers, I wrote this VBA but it is not working. Can someone please help?
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim sc1 As SlicerCache
Dim sc2 As SlicerCache
Dim sc3 As SlicerCache
Dim sc4 As SlicerCache
Dim SI1 As SlicerItem
Dim SI2 As SlicerItem
Dim SI3 As SlicerItem
Set sc1 = ThisWorkbook.SlicerCaches("Slicer_Community")
Set sc2 = ThisWorkbook.SlicerCaches("Slicer_Community1")
Set sc3 = ThisWorkbook.SlicerCaches("Slicer_Community2")
Set sc4 = ThisWorkbook.SlicerCaches("Slicer_Community3")
Application.ScreenUpdating = False
Application.EnableEvents = False
sc2.ClearManualFilter
sc3.ClearManualFilter
sc4.ClearManualFilter
For Each SI1 In sc1.SlicerItems
sc2.SlicerItems(SI1.Name).Selected = SI1.Selected
Next SI1
For Each SI2 In sc2.SlicerItems
sc3.SlicerItems(SI2.Name).Selected = SI2.Selected
Next SI2
For Each SI3 In sc3.SlicerItems
sc4.SlicerItems(SI3.Name).Selected = SI3.Selected
Next SI3
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim sc1 As SlicerCache
Dim sc2 As SlicerCache
Dim sc3 As SlicerCache
Dim sc4 As SlicerCache
Dim SI1 As SlicerItem
Dim SI2 As SlicerItem
Dim SI3 As SlicerItem
Set sc1 = ThisWorkbook.SlicerCaches("Slicer_Community")
Set sc2 = ThisWorkbook.SlicerCaches("Slicer_Community1")
Set sc3 = ThisWorkbook.SlicerCaches("Slicer_Community2")
Set sc4 = ThisWorkbook.SlicerCaches("Slicer_Community3")
Application.ScreenUpdating = False
Application.EnableEvents = False
sc2.ClearManualFilter
sc3.ClearManualFilter
sc4.ClearManualFilter
For Each SI1 In sc1.SlicerItems
sc2.SlicerItems(SI1.Name).Selected = SI1.Selected
Next SI1
For Each SI2 In sc2.SlicerItems
sc3.SlicerItems(SI2.Name).Selected = SI2.Selected
Next SI2
For Each SI3 In sc3.SlicerItems
sc4.SlicerItems(SI3.Name).Selected = SI3.Selected
Next SI3
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub