Cycle through Pivot Tables with Pivot Items

D

douglascfast

All,

I am having a few problems.

Situation:

I have 20 Pivot tables. Most have Country Code and all have a staton
code.

I need my code to
1) Get the first country code
2) Update all Pivot tables where country code exists in the Pivot table
3) Print it
4) Next country code

I have code to print the sheets to PDF
And the code below changes only one of my tables (Though it shows it is
referenceing all my tables)

Any ideas?

Code:

Sub Internet()
'Got this off the internet

Dim PI as PivotItem
Dim PF as PivotField
Dim I as Integer

' This allows the macro to run but still shows below it is doing
something to a
'Pivot table where the item does not exsist

On Error Resume Next

I = 0

Set PF = Worksheets("Test").Pivotfields("Country Cd")

For Each PT in worksheets("test").PivotTables

For Each PI in PF.PivotItems

PF.CurrentPage = PI.value

If worksheet('test").Range("B12") = "0" then
'Do nothing No data for the country
Else
I = I + 1
'Test Junk
Worksheets("sheet2").Cells(I,1) = PI.Value
' Sheet two lists all countrys with more than one record 20 times one
for each pivot table
' even though it only changed one pivottable
' Add call to print here
' MsgBox "Working on " & PT 'This shows all the pivot tables one at a
time even thought
'Its not doing anyting to
them
End IF
Next
Next PT

End Sub



So, how to get it to loop and how to avoid the pivot table with out
Country Cd in it?

Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top