Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all,
I have a pivot table that I dynamically generate off of a named field source, showing roles, names and hours per week. The trick is this - I have a pivot table that only shows 1 role ("painter"). But, when my users update the source data, they may add a new role to it, that's not marked as pivottable.items.role("builder").visible= false. so, if the new data introduces "Janitor" to my role field, my code won't have it marked as visible=false, because it wasn't there. Is there a way to code a loop based on pivot items. Something like: "Do While pivotitems.role<"Builder" pivotitems.visible=false" Right now i have about 120 different role.visible=false statements. :( Any help or code snippets would be greatly appreciated. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You could use code similar to the following:
Sub HidePivotItems() 'hide all pivot items in all tables on sheet 'except specified item Dim pt As PivotTable Dim pf As PivotField Dim pi As PivotItem On Error Resume Next For Each pt In ActiveSheet.PivotTables Set pf = pt.PivotFields("Role") pf.AutoSort xlManual, "Role" For Each pi In pf.PivotItems If pi.Value = "Painter" Then pi.Visible = True Else pi.Visible = False End If Next pf.AutoSort xlAscending, "Role" Next End Sub Randy wrote: Hi all, I have a pivot table that I dynamically generate off of a named field source, showing roles, names and hours per week. The trick is this - I have a pivot table that only shows 1 role ("painter"). But, when my users update the source data, they may add a new role to it, that's not marked as pivottable.items.role("builder").visible= false. so, if the new data introduces "Janitor" to my role field, my code won't have it marked as visible=false, because it wasn't there. Is there a way to code a loop based on pivot items. Something like: "Do While pivotitems.role<"Builder" pivotitems.visible=false" Right now i have about 120 different role.visible=false statements. :( Any help or code snippets would be greatly appreciated. -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Fantastic!! I knew there was a way to do it, just
couldn't construct the syntax. thanks a ton!! -----Original Message----- You could use code similar to the following: Sub HidePivotItems() 'hide all pivot items in all tables on sheet 'except specified item Dim pt As PivotTable Dim pf As PivotField Dim pi As PivotItem On Error Resume Next For Each pt In ActiveSheet.PivotTables Set pf = pt.PivotFields("Role") pf.AutoSort xlManual, "Role" For Each pi In pf.PivotItems If pi.Value = "Painter" Then pi.Visible = True Else pi.Visible = False End If Next pf.AutoSort xlAscending, "Role" Next End Sub Randy wrote: Hi all, I have a pivot table that I dynamically generate off of a named field source, showing roles, names and hours per week. The trick is this - I have a pivot table that only shows 1 role ("painter"). But, when my users update the source data, they may add a new role to it, that's not marked as pivottable.items.role("builder").visible= false. so, if the new data introduces "Janitor" to my role field, my code won't have it marked as visible=false, because it wasn't there. Is there a way to code a loop based on pivot items. Something like: "Do While pivotitems.role<"Builder" pivotitems.visible=false" Right now i have about 120 different role.visible=false statements. :( Any help or code snippets would be greatly appreciated. -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You're welcome!
Randy wrote: Fantastic!! I knew there was a way to do it, just couldn't construct the syntax. thanks a ton!! -----Original Message----- You could use code similar to the following: Sub HidePivotItems() 'hide all pivot items in all tables on sheet 'except specified item Dim pt As PivotTable Dim pf As PivotField Dim pi As PivotItem On Error Resume Next For Each pt In ActiveSheet.PivotTables Set pf = pt.PivotFields("Role") pf.AutoSort xlManual, "Role" For Each pi In pf.PivotItems If pi.Value = "Painter" Then pi.Visible = True Else pi.Visible = False End If Next pf.AutoSort xlAscending, "Role" Next End Sub Randy wrote: Hi all, I have a pivot table that I dynamically generate off of a named field source, showing roles, names and hours per week. The trick is this - I have a pivot table that only shows 1 role ("painter"). But, when my users update the source data, they may add a new role to it, that's not marked as pivottable.items.role("builder").visible= false. so, if the new data introduces "Janitor" to my role field, my code won't have it marked as visible=false, because it wasn't there. Is there a way to code a loop based on pivot items. Something like: "Do While pivotitems.role<"Builder" pivotitems.visible=false" Right now i have about 120 different role.visible=false statements. :( Any help or code snippets would be greatly appreciated. -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html . -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Pivot Table Items | Excel Discussion (Misc queries) | |||
Excel 2002: How to eliminate space within a cell and count items? | Excel Discussion (Misc queries) | |||
How to eliminate xero values from pivot table and list top 10 only | Excel Worksheet Functions | |||
Eliminate Duplicates in Pivot Table | Excel Discussion (Misc queries) | |||
Pivot Table- how do I eliminate duplicates in count of name | Excel Discussion (Misc queries) |