Code is below - I'm receiving this error and double-checked the name of my worksheet, pivottable and field name that is in the filter - any other ideas?
Sub Filter_Multiple_Pivots()
'Call the Filter Pivot macro on multiple pivots
Dim sFilter1 As String
Dim sFilter2 As String
'Set the filter criteria
sFilter1 = ThisWorkbook.Worksheets("Detail by Sup").Range("A27").Value
sFilter2 = ThisWorkbook.Worksheets("Detail by Sup").Range("B27").Value
'Call the filter pivot macro to filter both pivots
Call Filter_PivotField_Args("Detail by Sup", "PivotTable10", "Day", sFilter1)
Call Filter_PivotField_Args("Detail by Agent", "PivotTable1", "Day", sFilter2)
End Sub
Sub Filter_PivotField_Args( _
sSheetName As String, _
sPivotName As String, _
sFieldName As String, _
sFilterCrit As String)
'Filter a pivot table or slicer for a specific date or period
Dim pi As PivotItem
With ThisWorkbook.Worksheets(sSheetName).PivotTables(sPivotName).PivotFields(sFieldName)
'Clear all filter of the pivotfield
.ClearAllFilters
'Loop through pivot items of the pivot field
'Hide or filter out items that do not match the criteria
For Each pi In .PivotItems
If pi.Name <> sFilterCrit Then
pi.Visible = False
End If
Next pi
End With
End Sub
Sub Filter_Multiple_Pivots()
'Call the Filter Pivot macro on multiple pivots
Dim sFilter1 As String
Dim sFilter2 As String
'Set the filter criteria
sFilter1 = ThisWorkbook.Worksheets("Detail by Sup").Range("A27").Value
sFilter2 = ThisWorkbook.Worksheets("Detail by Sup").Range("B27").Value
'Call the filter pivot macro to filter both pivots
Call Filter_PivotField_Args("Detail by Sup", "PivotTable10", "Day", sFilter1)
Call Filter_PivotField_Args("Detail by Agent", "PivotTable1", "Day", sFilter2)
End Sub
Sub Filter_PivotField_Args( _
sSheetName As String, _
sPivotName As String, _
sFieldName As String, _
sFilterCrit As String)
'Filter a pivot table or slicer for a specific date or period
Dim pi As PivotItem
With ThisWorkbook.Worksheets(sSheetName).PivotTables(sPivotName).PivotFields(sFieldName)
'Clear all filter of the pivotfield
.ClearAllFilters
'Loop through pivot items of the pivot field
'Hide or filter out items that do not match the criteria
For Each pi In .PivotItems
If pi.Name <> sFilterCrit Then
pi.Visible = False
End If
Next pi
End With
End Sub