How to use a list box to select pivot table page fields

Skysurfer

Board Regular
Joined
Apr 19, 2004
Messages
202
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
Hi,

Is there a way to loop through all the page fields in a pivot table and mark them true/false based on selections in a multi select list box?

I have a dynamic list box on a user form that contains all the page fields, which are dynamic. What I need is to have the pivot table fields tie to whatever selections the user makes in the list box.

Here is the test code I have for changing the page fields:

Code:
Sub Macro5()

    With ActiveSheet.PivotTables("PVT_Chart01_SeriesData").PivotFields("Product")
        .PivotItems("Bass Amps").Visible = False
        .PivotItems("Cobalt").Visible = False
        .PivotItems("GTR Amps").Visible = True
        .PivotItems("Guitar Parts").Visible = True
        .PivotItems("Guitars").Visible = True
        .PivotItems("PAs").Visible = True
        .PivotItems("Speaker Parts").Visible = True
        .PivotItems("Speakers").Visible = True
        .PivotItems("(blank)").Visible = True
    End With

End Sub

I guess for a loop (if that is what works), I need to increment both the page field number and the list box index number???

Thanks,

Lawrence
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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