ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add fields to pivot table (https://www.excelbanter.com/excel-programming/294201-add-fields-pivot-table.html)

Lee

Add fields to pivot table
 
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.

Bill Renaud[_2_]

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.





All times are GMT +1. The time now is 05:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com