MercuryVBA
Board Regular
- Joined
- Nov 12, 2013
- Messages
- 56
Hello,
I am trying to write some code to synchronize two slicers that are linked to pivot tables that were created from a Power Pivot Data Model. I need to do this in the first place, because the data model is not properly working to control all of the tables with defined relationships properly.
The below code is a sample I got from Bill Jelen's channel and works for slicers created from regular pivot tables.
But when running it for Slicers created from Power Pivot Data Model pivot tables, it fails at sc1.SlicerItems and returns a 1004 runtime error.
Does anyone have any idea how to get around this? Thank you so very much
I am trying to write some code to synchronize two slicers that are linked to pivot tables that were created from a Power Pivot Data Model. I need to do this in the first place, because the data model is not properly working to control all of the tables with defined relationships properly.
The below code is a sample I got from Bill Jelen's channel and works for slicers created from regular pivot tables.
But when running it for Slicers created from Power Pivot Data Model pivot tables, it fails at sc1.SlicerItems and returns a 1004 runtime error.
Does anyone have any idea how to get around this? Thank you so very much
Code:
Private Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, ByVal Target As PivotTable)
Dim sc1 As SlicerCache
Dim sc2 As SlicerCache
Dim SI1 As SlicerItem
Set sc1 = ThisWorkbook.SlicerCaches("Slicer_Name")
Set sc2 = ThisWorkbook.SlicerCaches("Slicer_Name2")
Application.ScreenUpdating = False
Application.EnableEvents = False
sc2.ClearManualFilter
'Fails on this next line of code for Slicers created from Data Model Pivot Tables
For Each SI1 In sc1.SlicerItems
sc2.SlicerItems(ST1.Name).Selected = ST1.Selected
Next SI1
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub