How to select all pivot items with .PivotItems(?????).Visible = True

BOYAR

New Member
Joined
Jul 14, 2016
Messages
4
Hi Everyone,

Im trying to find easy solution on how to select all Pivot items. Things is that my data base is updated with new entries very often so i need to refresh pivot and then open filters and click on "select all" each time, and then un-check "blanks"

What i have now is :

Code:
Sub Pivot_upd()
'
' Pivot_upd Macro
'

'
    Sheets("Pivot").Select
    ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("Mfg. Part #")
        .PivotItems([B]"(Select ALL)"[/B]).Visible = True
        .PivotItems("(blank)").Visible = False
        
    End With
    
End Sub

Im not sure what is the proper command to be used instead of this "select all" ?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Ok found the solution:

Code:
Sub Pivot_upd()
'
' Pivot_upd Macro
'

'
    Sheets("Pivot").Select
    ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("Mfg. Part #")
        .ClearAllFilters
        .PivotItems("(blank)").Visible = False
                 
    End With
    
End Sub
 
Upvote 0
Thank you, Boyar. For some reason, when I tried recording the macro, I did not get that code. But, this time I did.

Still did not work like I wanted, but taking your suggestion I found the solution that works.

I have two pivot tables and created this sub which seems to do the job ...
  • Select all the items
  • Then de-select the pivot items that equal zero

VBA Code:
Sub RefeshPivots()

    Sheet4.PivotTables("PivotTable1").PivotCache.Refresh
        With Sheet4.PivotTables("PivotTable1").PivotFields("Years Total")
            .ClearAllFilters
            .PivotItems("$0").Visible = False
        End With
        
    Sheet4.PivotTables("PivotTable2").PivotCache.Refresh
        With Sheet4.PivotTables("PivotTable2").PivotFields("Years Total")
            .ClearAllFilters
            .PivotItems("$0").Visible = False
        End With

End Sub

Regards,

Steve
 
Upvote 0

Forum statistics

Threads
1,223,728
Messages
6,174,157
Members
452,548
Latest member
Enice Anaelle

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