Pivot table filter based on value using VBA code
Hi All,
The given below code filter the Pivot table based on cell value. I created this in module. But I want to implement this in specific worksheet "Market_MU Summary",
as I run this in "private sub procedure" with "change" event, the code just keep refreshing the pivots and doesn't stop even it hangs the excel.
Please any help on this.
Code:
Option Explicit
Sub Worksheet_Change1111()
Dim a As String
Dim pt As PivotTable
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Market_MU Summary")
Set pt = ws.PivotTables("PivotTable3")
' Activate the worksheet containing the PivotTable
'ThisWorkbook.Worksheets("Market_MU Summary").Activate
' Get the value from cell C3
a = Worksheets("Market_MU Summary").Cells(3, 33).Value
' Loop through all PivotTables in the active sheet
For Each pt In ActiveSheet.PivotTables
With pt.PivotFields("Uniq Count")
' Check if "Uniq Count" is a valid field in the PivotTable
If .Orientation = xlPageField Then
.ClearAllFilters
.CurrentPage = a
End If
End With
Next pt
End Sub