Hide all except one in a Pivot Field

shutter

New Member
Joined
Oct 29, 2006
Messages
4
Hi Everyone,

I have some pivot tables that contain 10's of thousands of data lines, and each line has a rep name in a PivotField "Rep". Rep names change dynamically and there are approximately 100 reps.
I want the ability to turn visibility off, of all reps in the pivot field, except when the rep field contains a string value of "repname".

This is to selectively copy data out to individual files that do not contain the full pivot source.

In effect, I want to accomplish the below by saying "make all reps not visble, except if name = Harry"

With ActiveSheet.PivotTables("PivotTable2").PivotFields("Rep")
.PivotItems("John").Visible = False
.PivotItems("Harry").Visible = True
.PivotItems("Fred").Visible = False
end with

I hope that makes sense!
Greg
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi Greg
Welcome to the board

You can loop through all the PTItems.

Code:
Sub SetPTIVis()
Dim PTI As PivotItem, sPTI As String

sPTI = "Mary"
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Rep")
    .PivotItems(sPTI).Visible = True
    For Each PTI In .PivotItems
        If PTI.Value <> sPTI Then PTI.Visible = False
    Next
End With
End Sub

Remark: If you have excel 2003 you may be able to simplify the code because there's a new option "Show all" in the PivotFields.

Hope this helps
PGC
 
Upvote 0
shutter

If you just want to split out the pivot table by Rep then set Rep as a page item.

You can then just right click and select Show Pages...
 
Upvote 0
Thank you for your help! I shall try that.

As for setting the rep field as a page item, yes, that would make it easier, but it needs to be a column field as the table is used as the source of other data where I require it to be a column field :)

Thank you,
Greg
 
Upvote 0

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top