Sub topic 11
Connecting One Control to Several PivotTables
This chapter assumes you can build a PivotTable from a range or Excel Table, insert a slicer or timeline, and select items in it. Here you will make one control filter several PivotTables at once.
Why connect controls
A new slicer or timeline filters only the PivotTable it was created from. A report with three PivotTables would then need three Region slicers. Report Connections lets one control drive all three, so a single click updates the whole report.
The shared pivot cache rule
A control can connect only to PivotTables that share its pivot cache. The pivot cache is the hidden copy of the source data that a PivotTable reads from.
- PivotTables created by copying an existing PivotTable, or by choosing the same source range or Table and accepting Excel's offer to reuse the data, share one cache.
- PivotTables created separately from the same range often get their own caches. They will not appear in the connection list.
- PivotTables built from different source ranges can never share a control.
Connecting a control in the Excel interface
- Click the slicer or timeline.
- Open the Slicer tab (or Timeline tab) on the ribbon.
- Choose Report Connections.
- In the dialog, tick each PivotTable that the control should filter.
- Select OK.
You can also right-click the control and choose Report Connections. The dialog lists every PivotTable in the workbook that shares the cache, grouped by sheet. A PivotTable that is missing from the list uses a different cache.
What happens after connecting
When you select an item, every connected PivotTable applies the same filter. Clearing the filter clears it everywhere. A timeline connects the same way, so one date range can filter every PivotTable on the sheet.
A connected PivotTable does not need the slicer field in its layout. A PivotTable can show Product and Sales only and still be filtered by a Region slicer.
Connecting through VBA
The same connection can be made in code. This macro adds the second PivotTable on the active sheet to an existing slicer cache. The cache name must match the one in your workbook, and both PivotTables must share a pivot cache.
Sub ConnectSlicerToSecondPivot()
Dim sc As SlicerCache
Set sc = ActiveWorkbook.SlicerCaches("Slicer_Region")
sc.PivotTables.AddPivotTable ActiveSheet.PivotTables(2)
End SubCommon errors
| Symptom | Likely cause | Fix |
|---|---|---|
| PivotTable missing from the Report Connections list | It uses a different pivot cache | Rebuild it by copying the first PivotTable |
| The VBA macro raises an error | The slicer cache name is wrong, or the PivotTables use different caches | Check the name on the Slicer tab, then confirm the cache |
| One PivotTable does not change | Its box is not ticked in the dialog | Reopen Report Connections and tick it |
Exercise
You created a Region slicer from PivotTable A. PivotTable B, built separately from the same range, does not appear in Report Connections. Why, and how can you fix it?
Show answer
PivotTable B has its own pivot cache, and a control connects only to PivotTables that share its cache. Rebuild B by copying and pasting PivotTable A, then change its fields. The copy shares A's cache and appears in the list.