help: update pivot table and printing it

MartinL

Well-known Member
Joined
Oct 16, 2008
Messages
1,141
Office Version
  1. 365
Platform
  1. Windows
Hi

I have 130 customers which I want to print out order forms for.
The way the spreadsheet is written is I am using a pivot table to select the customer which then populates nicly with some additional columns of lookup data, thhrown in for good measure.

The print area is set so i can select 1 at a time manually and it works great. My problem now, is that I need to print out a batch of these weekly, by pushing one button.

Can I get excel to loop through a
  • change the "report filter"
  • print worksheet

scenario until all the retailers orders have been printed
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
OK

So I have found this useful piece of code at Printing PivotTables &  PivotCharts. Print Each Page Field (Report Filter) Of Pivot Tables & Pivot Charts

Rich (BB code):
Sub Print_Batch()

Dim pt As PivotTable, pi As PivotItem, pf As PivotField
Dim lLoop As Long
 

Set pt = Sheet2.PivotTables("PTSuggOrd)
Set pf = Slicer_Store        'how do I do this?
 
For Each pi In pf.PivotItems
    pi.Value = pi.Value
    'Sheet1.PivotTables(1).PageFields(1).CurrentPage = pi.Value
    Sheet1.PrintOut
    lLoop = lLoop + 1
Next pi
End Sub
 
Upvote 0
I have decided for now to take my slicer and add it as a Report Filter

And it works in a fashion!
What I am finding now is that not all retailers make orders every week, typically 50% do
so the print function is currently printing out twice as many orders than is required
The slicer visually indicates items with no values, by greying them out.
Can I make use of this, so only orders with values are printed?
Martin
 
Upvote 0
simplistic way

change this
Code:
Sheet1.PrintOut

to
Code:
If Range("C17") <> "" Then Sheet2.PrintOut
where C17 is the first cell containing pivot data

so the whole macro looks like this

Code:
Sub Print_Batch()

Dim pt As PivotTable, pi As PivotItem, pf As PivotField
Dim lLoop As Long
 

Set pt = Sheet2.PivotTables("PTSuggOrd")
Set pf = pt.PageFields("Outlet")
 
For Each pi In pf.PivotItems
    Sheet2.PivotTables("PTSuggOrd").PageFields("Outlet").CurrentPage = pi.Value
    If Range("C17") <> "" Then Sheet2.PrintOut
    lLoop = lLoop + 1
Next pi
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,891
Members
449,194
Latest member
JayEggleton

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