VBA for Pivot Table Report Filter

thelostscott

Board Regular
Joined
May 7, 2010
Messages
226
Hi all,

Is there another way to write some code that will allow me to "Unselect" every option in a Report Filter for a Pivot Table, then "Select" 3 options only?

I have tried something like this to no avail:
Code:
ActiveSheet.PivotTables("PivotTable1").PivotFields("Business").CurrentPage = "(All)"

ActiveSheet.PivotTables("PivotTable1").PivotFields("Business").EnableMultiplePageItems = True
    
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Business")
        .PivotItems("(ALL)").Visible = False
        .PivotItems("Business 1").Visible = True
        .PivotItems("Business 2").Visible = True
        .PivotItems("Business 3").Visible = True
    End With
I have tried recording a macro but it generates a massive list of every option available =False, but this list will change every time I want to run this code and I don't it to keep pulling up errors just because some of the list has changed!

Thanks in advance ;)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try:
Code:
Dim PT As PivotTable
Dim i As Integer
Set PT = ActiveSheet.PivotTables(1)
    
    With PT.PivotFields("Business")
       ' .CurrentPage = "(All)"
        .EnableMultiplePageItems = True
        
        For i = 1 To .PivotItems.Count
            With .PivotItems(i)
                Select Case .Name
                
                Case "Business 1", "Business 2", "Business 3"
                    .Visible = True
                Case Else
                    .Visible = False
                End Select
            End With
        Next i
    End With
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

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