VBA: Printing from Pivot Table Filter

rstlhiii

New Member
Joined
Apr 29, 2019
Messages
5
I am attempting to Print multiple reports, based on a pivot table, after searching the web, I have found the below code.
This does work, it will cycle through the first filter field, and update the pivot table. However, it doesn't advance properly.
For example it will run through the For loop multiple times and print the same data multiple times before going to the next "pi".
I'm not sure what is causing this, and it's different for each one. Some values get printed out several times, others just a couple.

Needless to say I only need the value printed once, before advancing and printing the next value of "pi"

Any help would be appreciated.

Sub PrintFirstFilterItems()
'downloaded from contextures.com
'prints a copy of pivot table
'for each item in
'first Report Filter field

On Error Resume Next

Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem

Set ws = ActiveSheet
Set pt = ws.PivotTables(1)
Set pf = pt.PageFields(1)

If pf Is Nothing Then Exit Sub

For Each pi In pf.PivotItems
pt.PivotFields(pf.Name) _
.CurrentPage = pi.Name
'ActiveSheet.PrintOut 'for printing
ActiveSheet.PrintPreview 'for testing
Next pi
End Sub
 

Forum statistics

Threads
1,226,798
Messages
6,193,062
Members
453,773
Latest member
bclever07

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