3

Below gives me a Type Mismatch

I was inspired by the commented and working line, to make a simple macro to connect all Pivottables to all Slicers. I have a large dataset for which I want to choose various subsets with the slicer filters and then see all pivottables update...

Now, I believe this is very simple, glad if someone can help me out.

Sub ConnectSlicers_Pivottables()

'ActiveWorkbook.SlicerCaches("Slicer_Country").PivotTables.AddPivotTable_
(ActiveSheet.PivotTables("PivotTable1"))

Dim SC As SlicerCache
Dim PT As PivotTable

For Each SC In ActiveWorkbook.SlicerCaches
For Each PT In ActiveSheet.PivotTables

SC.PivotTables.AddPivotTable (PT)

Next PT
Next SC

End Sub
4

1 回答 1

0

是的,它不能直接工作。只需通过名称调用 PivotTable 进行小的调整:

sc.PivotTables.AddPivotTable (ActiveSheet.PivotTables(pt.Name))

于 2020-05-01T11:51:53.050 回答