VBA filter pivot table

I would like to choose "FO'", "PO", "SO", etc in the filter below.
I tried Value2:="PO", Value3:="SO" but get error

  Application.ScreenUpdating = False
     ActiveSheet.PivotTables("Ship").ManualUpdate = True

      ActiveSheet.PivotTables("Ship").PivotFields("Service Type").ClearAllFilters

      ActiveSheet.PivotTables("Ship").PivotFields("Service Type").PivotFilters. _
    Add Type:=xlCaptionEquals, Value1:="FO"

  ActiveSheet.PivotTables("Ship").ManualUpdate = False
  Application.ScreenUpdating = True

Open in new window

Euro5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Professor JMicrosoft Excel ExpertCommented:
if  you upload a dummy file, i can do it for you.

otherwise, you can record a macro while you set the filter and it will generate the code for ya.

also you can see different ways manipulating pivot table with vba in here
Rgonzo1971Commented:
Hi,

pls try

Application.ScreenUpdating = False
Set pt = ActiveSheet.PivotTables("Ship")
With pt
    .ManualUpdate = True

    .PivotFields("Service type").ClearAllFilters
        
    For Each PtItm In .PivotFields("Service type").PivotItems
        If PtItm.Name = "FO" Or PtItm.Name = "PO" Or PtItm.Name = "SO" Then
            PtItm.Visible = True
        Else
            PtItm.Visible = False
        End If
    Next
End With
Application.ScreenUpdating = True

Open in new window

Regards
Euro5Author Commented:
Rgonzo1971  Should PtItm be a variable?
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Rgonzo1971Commented:
Yes

Dim pt As PivotTable
Dim PtItm As PivotItem
Application.ScreenUpdating = False
Set pt = ActiveSheet.PivotTables("Ship")
With pt
    .ManualUpdate = True

    .PivotFields("Service type").ClearAllFilters
        
    For Each PtItm In .PivotFields("Service type").PivotItems
        If PtItm.Name = "FO" Or PtItm.Name = "PO" Or PtItm.Name = "SO" Then
            PtItm.Visible = True
        Else
            PtItm.Visible = False
        End If
    Next
End With
Application.ScreenUpdating = True

Open in new window

Excel amusantCommented:
Please try this

Dim ITEM As PivotItem
Application.ScreenUpdating = False
      ActiveSheet.PivotTables("Ship").PivotFields("Service Type").ClearAllFilters
For Each ITEM In ActiveSheet.PivotTables("Ship").PivotFields("Service Type").PivotItems
If Not ITEM = "FO" And Not ITEM = ("PO") And Not ITEM = ("SO") Then
        
        ITEM.Visible = False
    End If
     
    Next

  Application.ScreenUpdating = True

Open in new window

Euro5Author Commented:
Rgonzo1971 this selects the correct Service Types, but they are not displayed in the pivot.
I can see them in the Service Type drop down as checked, but the pivot is blank.
Is that unusual?
Euro5Author Commented:
Excel amusant that excludes the Service Types i need to include
Excel amusantCommented:
It includes the name which are listed in the code.

If you run the code the list will be filtered by FO, PO and SO the rest will not be visible.
Euro5Author Commented:
I uploaded a file - this may help.
What-if-scenario-v7.2.xlsm
Excel amusantCommented:
Please see attached. It does filter by FO, PO and SO.

Click on the macro button in sheet Temp.
What-if-scenario-v7.2.xlsm

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Euro5Author Commented:
You were right! So sorry and thanks very much!!
Excel amusantCommented:
You welcome, Glad it was helpful.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.