MercuryVBA
Board Regular
- Joined
- Nov 12, 2013
- Messages
- 56
Hello VBA MVPs,
The below code typically works for standard pivot tables, but fails on line 42 (oSc.SlicerItems.Count) under " 'Targeting the Slicer that needs to be synched" when trying to access SlicerItems in a SlicerCache linked to a Power Pivot Data Model Pivot Table.
Can anyone kindly help me with the syntax to overcome this hurdle? Thank you so very much. Ultimately I am trying to synchronize two Slicers in a sheet.
The below code typically works for standard pivot tables, but fails on line 42 (oSc.SlicerItems.Count) under " 'Targeting the Slicer that needs to be synched" when trying to access SlicerItems in a SlicerCache linked to a Power Pivot Data Model Pivot Table.
Can anyone kindly help me with the syntax to overcome this hurdle? Thank you so very much. Ultimately I am trying to synchronize two Slicers in a sheet.
Code:
Option Explicit
'Variable to prevent event looping:
Dim mbNoEvent As Boolean
Private Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, ByVal Target As PivotTable)
Dim oScPO As SlicerCache
Dim oScBgtTo As SlicerCache
Dim oSc As SlicerCache
Dim oPT As PivotTable
Dim oSi As SlicerItem
Dim bUpdate As Boolean
If mbNoEvent Then Exit Sub
mbNoEvent = True
bUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
For Each oSc In ThisWorkbook.SlicerCaches
For Each oPT In oSc.PivotTables
Debug.Print oPT.Parent.Name
Next
Next
'Setting/Assigning Variable when the ExDash Slicer is Clicked
For Each oSc In ThisWorkbook.SlicerCaches
For Each oPT In oSc.PivotTables
If oSc.Name = "SlicerPO" And oPT.Parent.Name = Target.Parent.Name Then
Set oScTO = oSc
MsgBox oScTO.Name, vbOKOnly
End If
Exit For
Next
If Not oScTO Is Nothing Then Exit For
Next
'Targeting the Slicer that needs to be synched
If Not oScTO Is Nothing Then
For Each oSc In ThisWorkbook.SlicerCaches
If (oSc.Name = "SlicerBgt") Then
oSc.SlicerItems(oSc.SlicerItems.Count).Selected = True
For Each oSi In oScTO.SlicerItems
On Error Resume Next
If oSc.SlicerItems(oSi.Value).Selected <> oSi.Selected Then
oSc.SlicerItems(oSi.Value).Selected = True
End If
Next
End If
Next
End If
mbNoEvent = False
Application.ScreenUpdating = bUpdate
End Sub