John_356
New Member
- Joined
- Jan 17, 2021
- Messages
- 26
- Office Version
- 365
- Platform
- Windows
Good day,
Browsing through the forum I have found this code which works for me. I would need an additional function, if J14 = "" then filter to ALL instead of Exit Sub:
Many thanks in advance.
John
Browsing through the forum I have found this code which works for me. I would need an additional function, if J14 = "" then filter to ALL instead of Exit Sub:
VBA Code:
[B]Private[/B] [B]Sub[/B] Worksheet_SelectionChange([B]ByVal[/B] Target [B]As[/B] Range)
If Intersect(Target, Range("J14")) Is Nothing Then Exit Sub
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
Set pt = Worksheets("sheet1").PivotTables("pivottable1")
Set Field = pt.PivotFields("Month")
NewCat = Worksheets("sheet2").Range("J14").Value
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
[B]End Sub[/B]
Many thanks in advance.
John