Pivot Table loop Filter

Comfy

Well-known Member
Joined
Dec 21, 2009
Messages
3,386
Good Morning.

I was hoping you could help me speed up this macro for looping through a Pivot Table Field and printing each out come.

Code:
Sub PrintAll()
Dim PT As PivotTable, pi1 As PivotItem, pi2 As PivotItem
Dim pvtFilter As String
Application.ScreenUpdating = False
pvtFilter = Range("A3").Value

Set PT = ActiveSheet.PivotTables(1)
With PT
   .ManualUpdate = True
   For Each pi1 In .PivotFields(pvtFilter).PivotItems
      pi1.Visible = True
      For Each pi2 In .PivotFields(pvtFilter).PivotItems
        If Not pi2.Name = pi1.Name Then pi2.Visible = False
      Next pi2
    ActiveCell.CurrentRegion.PrintOut Copies:=1
   Next pi1
   .ManualUpdate = False
End With
Application.ScreenUpdating = True
MsgBox "All Done :)"
End Sub

I originally did it this way as I was unsure how to unselect all the current items and just select the filter item. Hence the nested Loop.

/Comfy
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Does this have to be in a macro? I'd put the field in the page area, and then do the "Show Report Filter Pages", and print the resulting sheets from that.
 
Upvote 0
Nope doesn't need to be a Macro.

Could you explain a little more? My Pivot Table knowledge is some what lacking.
 
Upvote 0
Oh Nevermind.

Just looked at the Field Settings and found the Insert Page Break after each item.

Thanks Glenn.
 
Upvote 0
Oh good. If you need any more help, just post back ( and mention your version number ).
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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