I have three pivot tables in a workbook, and three slicers on one page next to one of the pivot tables. The pivot tables are all linked to the same data source. The three slicers are linked to the same fields in all three pivot tables (Product, Project & Supplier). I need to connect the slicers to the other two pivot tables. So if someone selects a product on the product slicer in sheet2, then it will filter sheet3 & sheet4.
Sheet1: Has the data
Sheet2 "Project": has a pivot table called ProjectPT and the three slicers (Project, Product & Supplier)
Sheet3 "Supplier": has a pivot table called SupplierPT
Sheet4 "Product": has a pivot table called ProductPT
Here is the code I have written for the slicer report connection. It is giving me a run-time error "424" Object Required on the bold row.
Thank you!
Sheet1: Has the data
Sheet2 "Project": has a pivot table called ProjectPT and the three slicers (Project, Product & Supplier)
Sheet3 "Supplier": has a pivot table called SupplierPT
Sheet4 "Product": has a pivot table called ProductPT
Here is the code I have written for the slicer report connection. It is giving me a run-time error "424" Object Required on the bold row.
Code:
Dim oScProduct As SlicerCache
Dim oScProject As SlicerCache
Dim oScSupplier As SlicerCache
Dim oSc As SlicerCache
Dim oPT As PivotTable
Dim oSi As SlicerItem
Dim sSupplier As String
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
If oPT.Name = Target.Name And oPT.Parent.Name = Target.Parent.Name Then
If oSc.Name Like "*Supplier*" Then
Set oScSupplier = oSc
ElseIf oSc.Name Like "*Product*" Then
Set oScProduct = oSc
ElseIf oSc.Name Like "*Supplier*" Then
Set oScSupplier = oSc
End If
Exit For
End If
Next
If Not oScSupplier Is Nothing And Not oScProduct Is Nothing And Not oScProject Is Nothing Then Exit For
Next
If Not oScSupplier Is Nothing Then
For Each oSc In ThisWorkbook.SlicerCaches
If Mid(oSc.Name, 7, 3) = Mid(oScSupplier.Name, 7, 3) And oSc.Name <> oScSupplier.Name Then
oSc.SlicerItems(oSc.SlicerItems.Count).Selected = True
For Each oSi In oScSupplier.SlicerItems
On Error Resume Next
If oSc.SlicerItems(oSi.Value).Selected <> oSi.Selected Then
oSc.SlicerItems(oSi.Value).Selected = oSi.Selected
End If
Next
End If
Next
End If
If Not oScProject Is Nothing Then
For Each oSc In ThisWorkbook.SlicerCaches
If Mid(oSc.Name, 7, 3) = Mid(oScProject.Name, 7, 3) And oSc.Name <> oScProject.Name Then
oSc.SlicerItems(oSc.SlicerItems.Count).Selected = True
For Each oSi In oScProject.SlicerItems
On Error Resume Next
If oSc.SlicerItems(oSi.Value).Selected <> oSi.Selected Then
oSc.SlicerItems(oSi.Value).Selected = oSi.Selected
End If
Next
End If
Next
End If
If Not oScProduct Is Nothing Then
For Each oSc In ThisWorkbook.SlicerCaches
If Mid(oSc.Name, 7, 3) = Mid(oScProduct.Name, 7, 3) And oSc.Name <> oScProduct.Name Then
oSc.SlicerItems(oSc.SlicerItems.Count).Selected = True
For Each oSi In oScProduct.SlicerItems
On Error Resume Next
If oSc.SlicerItems(oSi.Value).Selected <> oSi.Selected Then
oSc.SlicerItems(oSi.Value).Selected = oSi.Selected
End If
Next
End If
Next
End If
mbNoEvent = False
Application.ScreenUpdating = bUpdate
Last edited by a moderator: