
Originally Posted by
p45cal
This one is difficult to provide a robust solution to.
The Show report filter pages command makes multiple new sheets when the command is executed. There is no control over where the pivot tables go, new sheets are always created.
Two ways you might go:
1. Exceute the Show report filter pages for each pivot table, then go hunting for the newly created sheets and try to match up the similar names then move pivot tables around, then delete redundant sheets.
2. Instead of using the Show report filter pages command, try to simulate what it does by copying the pivot table according to what's selected in the page field(s), and set up the copied pivots in the same way as the Show report filter pages command would have. You do have control over where the copied pivots go.
Either way, a considerable amount of coding is required.
I suggest posting a brand new thread for this question.
Thanks p45cal. But I some how figured out for this, Have posted the code below, will be helpful for others in future
Sub Filter_Pages()
Dim i As Integer
Dim sItem As String
Dim pivotSht As Worksheet
Dim ws As Worksheet
Dim PT1 As PivotTable
Dim PT2 As PivotTable
Set pivotSht = Sheets("Master")
Application.ScreenUpdating = False
Set PT1 = pivotSht.PivotTables("10A")
Set PT2 = pivotSht.PivotTables("10B")
PT1.ShowPages PageField:="Building"
pivotSht.move Before:=Worksheets(1)
With PT2
With .PivotFields("Building")
.PivotItems(1).Visible = True '---hide all items except item 1
For i = 2 To .PivotItems.Count
.PivotItems(i).Visible = False
Next
For i = 1 To .PivotItems.Count
.PivotItems(i).Visible = True
If i <> 1 Then .PivotItems(i - 1).Visible = False
sItem = .PivotItems(i)
With PT2.PivotFields("Building")
.PivotItems(i).Visible = True
EnableMultiplePageItems = False
With PT2.TableRange2.Copy
Sheets(sItem).Activate
With ActiveSheet
Range("D1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End With
End With
End With
Next i
End With
End With
End Sub