Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pivot Table Automation

Status
Not open for further replies.

par60056

Programmer
Jul 16, 2001
31
0
0
US
I have created several pivot table from a sheet of source data. The pivot tables are the same regardless of the of the source of the data in the source sheet with 1 small exception. For 1 data source certain values are to be excluded.

This is easy enough, just

ActiveSheet.PivotTables("PivotTable2").PivotFields("name").PivotItems("DENVER").Visible = False

Now Denver will never be seen. However when I update the data from Data source 2 I want to see Denver. The obvious thing would be

ActiveSheet.PivotTables("PivotTable2").PivotFields("name").PivotItems("DENVER").Visible = True

and this is what is written if I macro record setting it back to visible. However if you include that in the script you get an error that says "Unable to set the Visible propert of the PivitItem class"

Any hints?
 
Hmmm...maybe this?

ActiveSheet.PivotTables("PivotTable2").PivotFields("name").CurrentPage = "(All)"


Also "name" may be a reserve word in VBA...you might want to consider changing it....I had a problem with "year"
 
Hi,
Am I understanding you correctly...

1. You have ONE Pivot Table and

2. You have TWO data sources?

3. You report on EITHER data source 1 OR data source 2 by changing the data range? Skip,
metzgsk@voughtaircraft.com
 
The pivot table is has a data source of columns A-M of the sheet named "rawData" This way the 3 different view in 3 different pivot tables don't need to go back to the source database.

All I have to do is change the single query in the rawData sheet to different time periods or client names and then refresh all the pivot tables. This way all of the pivot tables are always in sync with the same data.

ETID !!! You are Right You win the Prize.

If I change it from "name" to "city" it works.
 
I was wrong. Use of "name" is not the problem.

It did point me in the right direction. When I changed it from "name" to "city" it reset the autosort to manual. With autosort set to manual my original code works.
 
Try doing what you want with the macro recorder on....then you might get a hint as to what syntax that the pivot table is expecting.
 
I recorded what I wanted to do using the macro recorder.

I then ran the macro that it generated and got the same error. If you read my last post, you got me started on the path to enlightenment and I solved the problem.

If you create a pivot table, set the column field to autosort (field properties advanced), then select an item to hide. Now start the recorder, unhide the item and stop the recorder. Rehide the item and run the macro the recorder created. You will get an error when it tries to set visible to TRUE.

The solution is to turn autosort off, turn manualupdate on, then set the items.visible=True, turn manualupdate off and autosort back on. Obvious right? Well documented?

 
I recorded what I wanted to do using the macro recorder.

I then ran the macro that it generated and got the same error. If you read my last post, you got me started on the path to enlightenment and I solved the problem.

If you create a pivot table, set the column field to autosort (field properties advanced), then select an item to hide. Now start the recorder, unhide the item and stop the recorder. Rehide the item and run the macro the recorder created. You will get an error when it tries to set visible to TRUE.

The solution is to turn autosort off, turn manualupdate on, then set the items.visible=True, turn manualupdate off and autosort back on. Obvious right? Well documented?

 
It's an undocumented FEATRURE LOL Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top