View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Macro in Excel with Pivot table

Every sheet (each and every sheet???) has a pivottable named exactly the same
thing???

If yes...

dim wks as worksheet
for each wks in activeworkbook.worksheets
with wks.pivottables("Tableau croisé dynamique1").pivotfields("country")
.pivotitems("canada").visible = ....
...
end with
next wks

if you only want to run this on worksheets that have a pivottable and those
worksheets have exactly one pivottable, you can use:

dim wks as worksheet
for each wks in activeworkbook.worksheets
if wks.pivottables.count 0 then
with wks.pivottables(1).pivotfields("country")
.pivotitems("canada").visible = ....
...
end with
end if
next wks

If you have multiple pivottables per sheet and the name is not consistent, then
you'll have to be more careful--or name the pivottables nicely.






Martin wrote:

How can I ask the macro to run this the top sectionon every sheet that I
have. I want to create conditions in the top so I can change them easily and
run those conditions to the below sheets. (I have a total of 30 sheets)

With ActiveSheet.PivotTables("Tableau croisé
dynamique1").PivotFields("Country")
.PivotItems("Canada").Visible = False
.PivotItems("Europe").Visible = True
.PivotItems("US").Visible = True
.PivotItems("US/Can").Visible = True
.PivotItems("US/Canada").Visible = True
.PivotItems("(vide)").Visible = True

Sheets("Cktp E 26-32").Select
Sheets("Cktp E 30").Select
Sheets("Cktp E 36").Select
Sheets("Cktp G 26").Select
Sheets("Cktp G 30").Select
Sheets("Cktp G 36").Select
Sheets("Cktp I 30").Select
Sheets("Cktp I 36").Select


--

Dave Peterson