View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bill Renaud[_2_] Bill Renaud[_2_] is offline
external usenet poster
 
Posts: 117
Default Add fields to pivot table

Turn on the macro recorder, deselect a few of the codes you don't want, then
turn off the macro recorder. You should get code that looks similar to the
following. Replace the ".PivotItems("Item1").Visible = False" lines with a
For loop or something. This code assumes that PivotFields("FieldName") is a
row field, not a page field.

With ActiveSheet.PivotTables("PivotTable1").PivotFields ("FieldName")
.PivotItems("Item1").Visible = False
.PivotItems("Item2").Visible = False
.PivotItems("Item3").Visible = False
End With
--
Regards,
Bill


"Lee" wrote in message
...
Is there a way to limit the fields that are used in a
pivot table when adding with a VB procedure? For example,
I have a list of codes ranging from 1000 to 9000 that will
be used as the data source for a pivot table. However,
when I run code to add the pivot table, I want only codes
ranging between 7000 and 8999 to be in the pivot table.
Right now after adding the pivot I have to go through and
manually deselect all the codes I don't want, but this is
a great many codes.