Looping through report filters to change visibility doesn't work

后端 未结 2 1279
死守一世寂寞
死守一世寂寞 2020-12-21 02:42

I\'m trying to select one report filter, in this case Canada. That means the rest must be made invisible. This code works without issue:

Public Sub FilterPiv         


        
2条回答
  •  粉色の甜心
    2020-12-21 03:16

    Is this what you are trying?

    Sub Sample()
        Dim Pi As PivotItem
    
        With ActiveSheet.PivotTables("Epidemiology").PivotFields("COUNTRY")
    
            .PivotItems("Canada").Visible = True
    
            For Each Pi In .PivotItems
                If UCase(Pi.Value) = "CANADA" Then
                    Pi.Visible = True
                Else
                    Pi.Visible = False
                End If
            Next Pi
        End With
    End Sub
    

提交回复
热议问题