0

Well. I have a table named "ALL_INFO" on a Sheet in Excel and I made a Pivot table in other sheet, its name is "PIVOT_INFO". And I would like to know the way to link a table, and a pivot table using Slicers to filter information and it be reflected in both tables.

Anybody knows how I can do it?

Thank you in advance.

PoorChristmas
  • 55
  • 1
  • 2
  • 9
  • Have you Googled this? Searched this site? I know I've seen answers to similar questions... – ashleedawg Apr 02 '18 at 19:27
  • Possible duplicate of [Linked tables and Slicer in excel](https://stackoverflow.com/questions/46179386/linked-tables-and-slicer-in-excel) ...(and [a few hundred other answers](https://www.google.ca/search?q=link+a+Table+and+a+Pivot+Table+using+Slicers+in+Excel+site:stackoverflow.com&num=100&tbs=li:1) from this site alone.) – ashleedawg Apr 02 '18 at 19:29

1 Answers1

5

Create a Slicer for the PivotTable, and one for the Table. Make sure the PT Slicer is visible, and the Table Slicer is hidden somewhere where users can't see it. Then put this code in the Sheet Module corresponding to the worksheet where your PT is:

Option Explicit

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim sLastUndoStackItem As String
Dim sc_Pivot As SlicerCache
Dim sc_Table As SlicerCache
Dim si_Pivot As SlicerItem
Dim si_Table As SlicerItem

With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With

If Target.Name = "PivotTable1" Then '<= Change name as appropriate
    On Error Resume Next 'in case the undo stack has been wiped or doesn't exist
    sLastUndoStackItem = Application.CommandBars(14).FindControl(ID:=128).List(1) 'Standard Commandbar, undo stack
    'The above line doesn't seem to work in my version of O365 so we'll use the English language backup
    If sLastUndoStackItem = "" Then sLastUndoStackItem = Application.CommandBars("Standard").Controls("&Undo").List(1)
    On Error GoTo 0

    If sLastUndoStackItem = "Filter" Or sLastUndoStackItem = "Slicer Operation" Then

        Set sc_Pivot = ActiveWorkbook.SlicerCaches("Slicer_Data") '<= Change name as appropriate
        Set sc_Table = ActiveWorkbook.SlicerCaches("Slicer_Data1") '<= Change name as appropriate
        sc_Table.ClearAllFilters

        On Error Resume Next 'In case items differ between Table and PT
        For Each si_Pivot In sc_Pivot.SlicerItems
            With si_Pivot
                sc_Table.SlicerItems(.Name).Selected = .Selected
            End With
        Next si_Pivot
    End If
End If

With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With

End Sub

Here's how things look before I use the "Master" slicer:

enter image description here

...and here's how things look after I use the "Master" slicer:

enter image description here

Note that filtering a Table hides rows in the entire worksheet. So you don't want to put anything that you want to remain visible at all times alongside the Table.

jeffreyweir
  • 4,668
  • 1
  • 16
  • 27
  • Hi Jeff , Do you Have any video Tutorial for this . since i have the same problem. i'm trying to control pivot table and excel table by single slicer but unable to do so..I tried pasting your code on the Pivot sheet in macro ..its still not working as shown above – Jitesh Vacheta Feb 23 '20 at 06:33
  • Hi Jitesh. What is the name of your PivotTable? – jeffreyweir Feb 24 '20 at 09:57
  • Hi Jeff , basically i have convert all the datasource into an excel table (Ctr + T) so in case i add any new value it will automatically add to my pivot table.Now question here is i have created two slicer one from the excel table the and the other is from this pivot table. For your reference i have attached the sample file ( Example.xlsx ) https://github.com/supersaiyan12/Query You'll find "DataSource_Tab" & "Pivot_Tab". if i change in the one slicer if doesn't make any impact on the other slicer. – Jitesh Vacheta Mar 03 '20 at 17:15