OzGrid

Excel VBA: Hide/Show Pivot Table Field Items

< Back to Search results

 Category: [Excel]  Demo Available 

Excel VBA: Hide/Show Pivot Table Field Items

 

Excel VBA: Hide/Show Pivot Table Field Items. Hiding/Showing Pivot Table Field Items

 

Hide/Show Pivot Table Field Items

Those of you that use pivot tables will be well aware of their power. Lets look at how we can use Excel VBA to show or hide Pivot Table Field Items.  The Excel macro below should give you a good idea how this can be done.

Sub HideShowFields()

Dim pt As PivotTable

Dim pi As PivotItem



    Set pt = ActiveSheet.PivotTables("MyPivot")

    'Speeds up code dramatically

    pt.ManualUpdate = True

    

    

        For Each pi In pt.PivotFields("Head1").PivotItems

        '+0 Forces text number value to real number

            Select Case pi.Value + 0

                Case 1 To 5

                    pi.Visible = False

                Case Else

                    pi.Visible = True

            End Select

        Next pi

    

    pt.ManualUpdate = False

 

End Sub

See also:

Printing PivotTables & PivotCharts
Refresh Pivot Table via VBA
Excel VBA Macro Codes Tips & Tricks
Excel Message Box (MsgBox) Function
Multi Select ListBox
Return Date of the First, or nth Day of Month

 

See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)