thatfarooq
New Member
- Joined
- Jul 29, 2024
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
I wrote this code to change different pivot filters in order to compute different values each time (region level, subregional level, MBU level, and FID level). The filter changes when I use the slicers connected to the pivot table. How to ensure that the filter is reset once I the cell value changes? I have mentioned "xPField.ClearAllFilters" in each case but it does not seem to work, any solutions?
VBA Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim xPTable As PivotTable
Dim xPField As PivotField
Dim xValue As String
Set xPTable = Worksheets("Calc").PivotTables("RegionBackend")
xValue = Worksheets("Calc").Range("B2").Value
Select Case xValue
Case Is = "North":
Set xPField = xPTable.PivotFields("Region")
Application.EnableEvents = False
xPField.ClearAllFilters
xPField.CurrentPage = xValue
xPTable.RefreshTable
Application.EnableEvents = True
Case Is = "North 1":
Set xPField = xPTable.PivotFields("Subregion")
Application.EnableEvents = False
xPField.ClearAllFilters
xPField.CurrentPage = xValue
xPTable.RefreshTable
Application.EnableEvents = True
Case Is = "N-JLM-08":
Set xPField = xPTable.PivotFields("MBU")
Application.EnableEvents = False
xPField.ClearAllFilters
xPField.CurrentPage = xValue
xPTable.RefreshTable
Application.EnableEvents = True
Case Is = "6442":
Set xPField = xPTable.PivotFields("FID")
Application.EnableEvents = False
xPField.ClearAllFilters
xPField.CurrentPage = xValue
xPTable.RefreshTable
Application.EnableEvents = True
End Select
End Sub