Help please with syntax

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I have a workbook named "Cost Pools"
There's a sheet named "Pivots"

On that sheet, there are a bunch of pivot tables. I've
given each one a name with the properties dialog.

Right now here's the code I use:

Sheets("Pivots").Select
ActiveSheet.Pivots("Retail").PivotSelect "", xlDataOnly
Selection.ShowDetail = True
ActiveSheet.Name = "Retail"

If I have 50 pivot table on that sheet, I have to repeat
the code 50 times. Here's what I'd like to do but I can't
figure out how:

For each pivot table name in "Pivots"
ActiveSheet.Pivots("name").PivotSelect "", xlDataOnly
Selection.ShowDetail = True
ActiveSheet.Name = "Pivot Table Name"
Next pivot table

Thanks for any help.
 
not tested:

dim ptCtr as long
for ptctr = 1 to worksheets("pivots").pivottables.count
with .pivottables(ptCtr)
.pivotselect.....
end with
next ptCtr

maybe even (equally untested):

dim PT as pivottable
for each pt in worksheets("pivots").pivottables
with pt
.pivotselect....
end with
next pt
 

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

Back
Top