Hide all pivotitems except 2 w-VBA

jakeman

Active Member
Joined
Apr 29, 2008
Messages
325
Office Version
  1. 365
Platform
  1. Windows
Hello everyone - I grabbed some code from another site on how to set all pivotitems = false except two items I want to display. It seems like it should be straightforward but I keep getting the following error:

Code:
 Run-time error '438': Object doesn't support this property or method

Here is the VBA code I am using:

Code:
Sub hidepivotitems()
'
'
    Dim oPI As PivotItem
    
    For Each oPI In ActiveSheet.PivotTables("PivotTable2").PivotFields("User")
        Select Case oPI.Name
            Case "Smith, Joe", "Black, Joe"
            Case Else
                oPI.Visible = False
        End Select
    Next oPI
    
End Sub

I am using VBA 7.0 on Excel 2010. Also, the code is failing on the "For Each oPI" line.

Thanks.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
trying to revive this old thread as i have a similar issue; the above code works but i am also trying to add a line that resets the pivot table to show all and then sorts based on case select. so far i haven't been able to get it working.

Code:
Sub DigitSplit8()
'
' Macro14 Macro
'


    Dim oPI As PivotItem




    For Each oPI In ActiveWorkbook.Worksheets("60Day").PivotTables("Test").PivotFields("Digit").PivotItems
        oPI.Visible = True
        Select Case oPI.Value
            Case "80", "81", "82", "83", "84", "35", "86", "87", "88", "89"
            Case Else
                oPI.Visible = False
        End Select
    Next oPI


End Sub
'
Sub DigitSplit9()
'
' Macro14 Macro
'


    Dim oPI As PivotItem


    For Each oPI In ActiveWorkbook.Worksheets("60Day").PivotTables("Test").PivotFields("Digit").PivotItems
       oPI.Visible = True
        Select Case oPI.Value
            Case "90", "91", "92", "93", "94", "95", "96", "97", "98", "99"
            Case Else
                oPI.Visible = False
        End Select
    Next oPI


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,552
Messages
6,120,172
Members
448,948
Latest member
spamiki

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