PivotTable VBA across 2 pivots

malloc

New Member
Joined
Aug 18, 2011
Messages
8
Apologies if this has been answered, I'm struggling to know what to search for as I don't know what I'm doing is "called".

I have two pivots tables of the same data, just displayed differently for reporting purposes, i.e. one has a timeline running vertically, the other horizontally. They are controled by slicers which are connected to both pivots. However I want to be able to ShowDetail in one and at the same time to ShowDetail in the other.

If that doesn't make much sense, the code view is:

ActiveSheet.PivotTables("PivotTable1").PivotFields("FIELD1").PivotItems("Item1").ShowDetail = True 'having changed from False

and upon changing from False to True in PivotTable1, I want this change to be applied to PivotTable2. It feels like it should be quite straightforward, but I'm struggling. I want to pass the command which has been applied to PivotTable1 to PivotTable2 but don't know how to do it.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
The code I've been trying (and failing with) is below. I don't like the code as it seems unneccessarily cumbersom, but sadly I get an error in any case:

Sub Macro1()

Dim i, j As Integer
i = 0
j = 0

For Each pf In Sheet4.PivotTables("PivotTable1").PivotFields
i = i + 1
For Each pi In pf.PivotItems
j = j + 1
Sheet4.PivotTables("PivotTables1").PivotFields(i).PivotItems(j).ShowDetail = Sheet2.PivotTables("PivotTables2").PivotFields(i).PivotItems(j).ShowDetail
Next pi
Next pf

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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