Im trying to filter a pivot table column (GP#
) from an array (shortened in this example).
The filter does work but when I get to a number (in this case 83292
) that is not in the filter, the excel crashes with the error :
Runtime error 1004, application-defined or object-defined error
Is there a way of checking if a number/name etc is in the filter and if it is then apply to filter?
My code:
vGP = Array("83041", "83327", "83292")
ActiveSheet.PivotTables("PivotTable1").ManualUpdate = True
With ActiveSheet.PivotTables("PivotTable1").PivotFields("GP#")
.PivotItems(1).Visible = True
' below code ensure pivot table filter does not cause error by not having anything in the filter
For i = 2 To .PivotItems.Count
.PivotItems(i).Visible = False
If .PivotItems(i).Visible Then .PivotItems(i).Visible = False
Next i
' goes through array and adds any value in array
For Each i In vGP
.PivotItems(i).Visible = True
Next i
On Error GoTo 0
Can anyone please help ensuring that the values in the array can be added to the filter and values in the array that are not present in the pivot table are ignored