Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Hide all PivotItems except for a specific Item

I really hope someone can help me with this. I am trying to make visible a
specified Pivot Item within a specific PivotField within a specific Pivot
Table. I have been trying to adapt some code to hide all Pivot Items for all
RowFields for all PivotTables but I haven't been very successful at it. Any
help I could get would be greatly appreciated.

Sub Shell()
Run SpecPivotItemsVisible("PivotTable6", "Country", "US")
End Sub

Sub SpecPivotItemsVisible(PivotTbl As String, PivField As String, PivItem As
String)
'hide all pivot items in all tables on sheet
'except last item
Dim pt As PivotTable 'Pivot table
Dim pf As PivotField 'Pivot field
Dim pi As PivotItem ' specific pivot item
Dim opi As PivotItem 'other pivot items


pt = Worksheets("Hidden).PivotTables(PivotTbl).value
pf = pt.PivotFields(PivField)
pi = pf.PivotItems(PivItem)

On Error Resume Next

With Worksheets("Hidden").PivotTables(pf)
RowField("gee").AutoSort xlManual
For Each opi = not pi In PivotField("pf").PivotItems
pi.Visible = False
Next
RowField("pf").AutoSort xlManual
End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Hide all PivotItems except for a specific Item

The following code should work:

'=================================
Sub Shell()
SpecPivotItemsVisible "PivotTable6", "Country", "US"
End Sub
'==============================
Sub SpecPivotItemsVisible(PivotTbl As String, PivField As String,
PivItem As String)
'hide all pivot items in all tables on sheet
'except last item
Dim pt As PivotTable 'Pivot table
Dim pf As PivotField 'Pivot field
Dim pi As PivotItem ' specific pivot item

For Each pt In Worksheets("Hidden").PivotTables
Debug.Print pt.Name
Next pt

Set pt = Worksheets("Hidden").PivotTables(PivotTbl)

Set pf = pt.PivotFields(PivField)

On Error Resume Next

pt.ManualUpdate = True

With pf
.AutoSort xlManual, .SourceName
.PivotItems(PivItem).Visible = True
For Each pi In .PivotItems
If pi.Name < PivItem Then
pi.Visible = False
End If
Next
.AutoSort xlAscending, .SourceName
End With

pt.ManualUpdate = False

End Sub

'=====================================

DynamiteSkippy wrote:
I really hope someone can help me with this. I am trying to make visible a
specified Pivot Item within a specific PivotField within a specific Pivot
Table. I have been trying to adapt some code to hide all Pivot Items for all
RowFields for all PivotTables but I haven't been very successful at it. Any
help I could get would be greatly appreciated.

Sub Shell()
Run SpecPivotItemsVisible("PivotTable6", "Country", "US")
End Sub

Sub SpecPivotItemsVisible(PivotTbl As String, PivField As String, PivItem As
String)
'hide all pivot items in all tables on sheet
'except last item
Dim pt As PivotTable 'Pivot table
Dim pf As PivotField 'Pivot field
Dim pi As PivotItem ' specific pivot item
Dim opi As PivotItem 'other pivot items


pt = Worksheets("Hidden).PivotTables(PivotTbl).value
pf = pt.PivotFields(PivField)
pi = pf.PivotItems(PivItem)

On Error Resume Next

With Worksheets("Hidden").PivotTables(pf)
RowField("gee").AutoSort xlManual
For Each opi = not pi In PivotField("pf").PivotItems
pi.Visible = False
Next
RowField("pf").AutoSort xlManual
End With

End Sub



--
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 Change PivotItems - Visible/Hide with VBA [email protected] Excel Worksheet Functions 3 January 6th 07 12:26 AM
How to hide an item subtotal in the row field? Daniel Excel Discussion (Misc queries) 1 December 22nd 06 07:15 PM
Count Specific Item in Specific Row RayH Excel Discussion (Misc queries) 9 July 23rd 06 07:48 PM
Excel 2003 Hide PivotItems Lee Excel Worksheet Functions 1 January 21st 05 08:41 PM
Add PivotItems to PivotTable / Enabling - Disabling PivotItems Ole[_3_] Excel Programming 1 July 8th 03 03:24 PM


All times are GMT +1. The time now is 12:33 AM.

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

About Us

"It's about Microsoft Excel"