VBA Pivot Choosing more than 1 choice on the filter field.

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
758
Hello friends, hope all is well!

please help me I am trying to choose more than one choice on a pivot table with VBA.
But didn't succeeded.

Your time & Effort is really appreciated!


Code:
Sub AAA()

    Sheets("PTDocRev").Select
    ActiveSheet.PivotTables("DrMnAct").PivotFields("Visit Count").CurrentPage = _
        "(All)"
    With ActiveSheet.PivotTables("DrMnAct").PivotFields("Visit Count")
        
        .PivotItems(" - ").Visible = False
        .PivotItems(" 1 ").Visible = False
        .PivotItems(" 2 ").Visible = False
        .PivotItems(" 3 ").Visible = False
        .PivotItems(" 4 ").Visible = False
        .PivotItems(" 5 ").Visible = False
        .PivotItems(" 6 ").Visible = False
        .PivotItems(" 7 ").Visible = False
        .PivotItems(" 8 ").Visible = False
        .PivotItems(" 9 ").Visible = False
        .PivotItems(" 10 ").Visible = False
    End With
End Sub

I tried the below code, but it didn't work.
Code:
Sub AAA()
    Sheets("PTDocRev").Select
    ActiveSheet.PivotTables("DrMnAct").PivotFields("Visit Count").CurrentPage = _
        "(All)"
    With ActiveSheet.PivotTables("DrMnAct").PivotFields("Visit Count")
        
        .PivotItems(" - ", " 1 ", " 2 ", " 3 ", " 4 ", " 5 ", " 6 ", " 7 ", " 8 ", " 9 ", " 10 ").Visible = False
    End With
End Sub
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Record a Macro to get started.
Before recording though, choose some filtering values for all fields in the Filter.
Start Recording. Reset the Filters to show all. Then make a Filter selection for each field in the filters. Stop recording.

You want your macro to reset the filter conditions to no filters because of the way they get applied. Also gives you a quick way to reset.
Usually I find the recorded method just fine to create macros that can be accessed through a button for specific complex filter conditions, even if using Slicers is easy.
 
Upvote 0

Forum statistics

Threads
1,216,111
Messages
6,128,898
Members
449,477
Latest member
panjongshing

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