Macro to select all filters in a pivot table apart from one which stays the same every time

saraapple

Board Regular
Joined
Feb 3, 2020
Messages
165
Office Version
  1. 2010
Platform
  1. Windows
I have tries to record a macro to select all data from a filter in a pivot table except one - however the macro recorder is too specific to the data I am currently using which is no good as the data changes daily.
This is what it creates:

Sub pivot()
'
' pivot Macro
'

'
Sheets("PIVOT").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("Description").CurrentPage _
= "(All)"
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Description")
.PivotItems("ORDERED 16/09/2022").Visible = True
.PivotItems("ORDERED 23/09/2022").Visible = True
.PivotItems("ORDERED 22/09/2022").Visible = True
.PivotItems("ORDERED 28/09/2022").Visible = True
.PivotItems("ORDERED 13/09/2022").Visible = True
.PivotItems("ORDERED 29/09/2022").Visible = True
.PivotItems("ORDERED 26/09/2022").Visible = True
.PivotItems("ORDERED 27/09/2022").Visible = True
End With
End Sub

How can I change this so all data is displayed apart from SALVAGE?
When I recorded the macro I selected ALL and then deselected SALVAGE however the macro I have created lists the items on display which change as they are dates!

I have to admit I am not great with macros and rely heavily on the recorder, which normally works but not this time.
Any help would be greatly appreciated.
Sara
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Something like:

VBA Code:
' blah removed for brevity

    Dim pvtIter As PivotItem
    
    For Each pvtIter In ActiveSheet.PivotTables("PivotTable2").PivotFields("Description")
        
        If pvtIter.Name = "SALVAGE" Then
            pvtIter.Visible = False
        Else
            pvtIter.Visible = True
        End If
        
        
    Next pvtIter
 
Upvote 0

Forum statistics

Threads
1,223,993
Messages
6,175,838
Members
452,675
Latest member
duongtruc1610

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