Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to eliminate any new pivot Items

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default How to eliminate any new pivot Items

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to eliminate any new pivot Items

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default How to eliminate any new pivot Items

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
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
Pivot Table Items Alan B Excel Discussion (Misc queries) 3 May 4th 08 06:24 PM
Excel 2002: How to eliminate space within a cell and count items? Mr. Low Excel Discussion (Misc queries) 6 November 24th 06 01:53 PM
How to eliminate xero values from pivot table and list top 10 only Dinesh Excel Worksheet Functions 0 February 19th 06 03:48 AM
Eliminate Duplicates in Pivot Table roadkill Excel Discussion (Misc queries) 2 February 3rd 06 06:13 PM
Pivot Table- how do I eliminate duplicates in count of name Isabelga Excel Discussion (Misc queries) 1 January 16th 06 06:15 PM


All times are GMT +1. The time now is 11:48 PM.

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"