SanjayGMusafir
Well-known Member
- Joined
- Sep 7, 2018
- Messages
- 1,513
- Office Version
- 2024
- Platform
- Windows
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
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