Hide Pivot Items by Keyword

  • I'm trying to hide pivot items containg a keyword. For example, if the pivot item contains the word 'CREDIT', I want to hide/deselect that row. I think the following code is close but it's not working. Any help is appreciated. (currently it cycles through all the pivot items but doesn't hide any of the rows where the word credit appears)


    Code
    Sub HidePivotItems()
        Dim pt As PivotTable, pi As PivotItem
        Set pt = ActiveSheet.PivotTables("PivotTable1")
              
        For Each pi In pt.PivotFields("Agency").PivotItems
            pi.Visible = Not pi.Name Like "CREDIT"
          
        Next pi
    End Sub
  • Re: Hide Pivot Items by Keyword


    See if this does what you want.



    HTH Cheers

    [SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

  • Re: Hide Pivot Items by Keyword


    I'll try that but it looks like it's only going to hide items with that exact name....I want to hide any row containing that keyword appearing in the name/pivot item

  • Re: Hide Pivot Items by Keyword


    Update this line


    Code
    If pi.Name = "CREDIT" Then


    to

    Code
    If pi.Name Like "CREDIT" Then

    [SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!