With code, which is very slow.
I named the range of Filter ID's, H5:H21, as FAILED
Function CheckValue(Value As Long, DataTable As Range) As Boolean
On Error Resume Next
CheckValue = (Application.WorksheetFunction.Match(Value, DataTable, 0) > 0)
Exit Function
End Function
Sub FilterPTItems()
Dim rngFailed As Range
Dim pvtTable As PivotTable
Dim pvtField As PivotField
Dim pvtItem As PivotItem
Dim blnShow As Boolean
Set rngFailed = ThisWorkbook.Names("FAILED").RefersToRange
Set pvtTable = ThisWorkbook.Worksheets("SN Retest").PivotTables(1)
Set pvtField = pvtTable.PivotFields("Serial_num")
Application.ScreenUpdating = False
On Error Resume Next
For Each pvtItem In pvtField.PivotItems
pvtItem.Visible = CheckValue(CLng(pvtItem.Value), rngFailed)
Next
Application.ScreenUpdating = True
End Sub
A quicker approach is to add a field to your pivot chart data source and use that as the page field.
I added a new field, called SERIAL_FILTER, with the following formula.
=MATCH(A2,FAILED,0)>0
Update the data source to include the new field and then used as the Page field showing TRUE.
Bookmarks