VBA to Filter Pivot Table Columns Labels using Filter List

SanjayGMusafir

Well-known Member
Joined
Sep 7, 2018
Messages
1,503
Office Version
  1. 2021
Platform
  1. MacOS
Hi Experts
Reference to my older post - VBA to Filter Column Labels using Filter List

I got help from one of the experts at the forum.

Until recently the below code was working well. Today when I actually needed to use filter I realized the code clears all filter from columns labels but does not filter them back.

I tried hard to understand where things might be going wrong. But Couldn't.

Please help me.
Thanks in advance

VBA Code:
'To Filter D1 Field as per the given Range - But ask before using filter
    Dim x1 As Integer
    x1 = MsgBox("Do you want to Filter Columns?", vbQuestion + vbYesNo + vbDefaultButton1, "")
   
    If x1 = vbYes Then
        Dim PI As PivotItem, FAr() As Variant, AI As Variant, bEx As Boolean, n As Long
       
        Application.ScreenUpdating = False
       
        FAr = Range("PFilters[Name]").Value
       
        With ActiveSheet.PivotTables("ExpAnalysis").PivotFields("D1").ClearAllFilters
            n = 0
            For Each PI In .PivotItems
                bEx = False
            For Each AI In FAr
            If LCase(AI) = LCase(PI.Value) Then
                bEx = True
                Exit For
            End If
            Next
            If bEx = False Then
                n = n + 1
                If n < .PivotItems.Count Then
                  PI.Visible = False
                Else
                  .ClearAllFilters
                End If
            End If
        Next
        End With
   
    Application.ScreenUpdating = True
   
    Else
    End If
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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