Urgently Seeking VBA Help Please!... To Synchronize Slicers Linked To Power Pivot Data Model Pivot Tables

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.

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
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top