LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Changing Pivot Table Fields Programmatically

Hey guys

I have allot of possible fields in my pivot table, however
I only need to display 3 fields at a time. I have
recorded a macro that will programmatically change the
fields, however I am running into a problem. For example
I have a Pivot Table that is currently displaying Average
of % Overdue19, Sum of On Time19, and Sum of Total19 in
the data part of the table. I have recorded a macro that
will remove those fields from the data part of the table
and in place, display the Average of % Overdue, Sum of On
Time, and Sum of Total instead. This code works perfectly
IF the current fields in the data part of table are
Average of % Overdue19, Sum of On Time19, and Sum of
Total19. If there are any other field names that are in
the data part of the field, then I get the error "Run-time
error '1004': Unable to get the PivotFields property of
the PivotTable class."

The reason I get this error is because the fields cannot
be found in the data part of the table because other field
names are there instead of the fields specified to
remove. How do I make the code say hide whatever fields
are currently in the data part of the pivot table and then
display whatever I specifiy in the code?

Below is my code as it is now:

Sheets("Pivot WOW REPS").Select
Range("B8").Select
ActiveSheet.PivotTables("PivotTable1").AddFields
RowFields:=Array( _
"Employee Name", "Data"), PageFields:=Array
("Department", "AD", "Supervisor")
ActiveSheet.PivotTables("PivotTable1").PivotFields
("Sum of Total19"). _
Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable1").PivotFields
("Average of % Overdue19"). _
Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable1").PivotFields
("Sum of On Time19"). _
Orientation = xlHidden
With ActiveSheet.PivotTables("PivotTable1").PivotFields
("On Time")
.Orientation = xlDataField
.Caption = "Sum of On Time"
.Position = 1
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields
("% Overdue")
.Orientation = xlDataField
.Caption = "Average of % Overdue"
.Position = 2
.Function = xlAverage
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields
("Total")
.Orientation = xlDataField
.Caption = "Sum of Total"
.Function = xlSum
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields
("Data").PivotItems( _
"Sum of On Time").Position = 1
ActiveSheet.PivotTables("PivotTable1").PivotFields
("Data").PivotItems( _
"Average of % Overdue").Position = 2
ActiveSheet.PivotTables("PivotTable1").PivotFields
("Data").PivotItems( _
"Sum of Total").Position = 3

Thank you

Todd Huttenstine
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem inserting calculated pivot fields into Pivot Table (2007) wamiller36 Excel Discussion (Misc queries) 1 March 5th 10 11:40 PM
fields names do not show in excel 2007 pivot table fields list marlo17 New Users to Excel 2 December 1st 08 01:25 PM
Pivot table: how to programmatically format headers? Dave O Excel Discussion (Misc queries) 3 October 9th 06 03:19 PM
number of fields in the row fields in pivot table UT Excel Discussion (Misc queries) 0 April 13th 06 01:17 AM
changing sort for pivot table fields Stan R Excel Programming 1 August 16th 03 12:32 PM


All times are GMT +1. The time now is 08:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"