I have a pivot table called Fiscal53_Data. One PivotFields, the "Check#" is already filtered to show only total check greater than $10K. From the same pivot table, I want to deselect Vendor Names, "Bank of Marin" and "Bank of Mellon" if it exists. I got the following code but the code for deselecting "Bank of Marin" actually makes the pivot table disappeared. How do I fix the code below?
VBA Code:
With ActiveSheet.PivotTables("Fiscal53_Data").PivotFields("Total")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "#,##0.00" 'Format Number
.Name = "Sum of Total"
'Pivot Table Tabular View
With ActiveSheet.PivotTables("Fiscal53_Data")
.InGridDropZones = True
.RowAxisLayout xlTabularRow
End With
ActiveSheet.PivotTables("Fiscal53_Data").PivotFields("Check#").PivotFilters. _
Add2 Type:=xlValueIsGreaterThan, DataField:=ActiveSheet.PivotTables( _
"Fiscal53_Data").PivotFields("Sum of Total"), Value1:=10000 'Filter Check# Column that has a total bigger than $10K
Columns("D:D").Select
Selection.Replace What:="(blank)", REPLACEMENT:="Direct Pay", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
End With
Dim pt As PivotTable, pi As PivotItem
For Each pt In Data_Pivot.PivotTables
If pt.Name = "Fiscal53_Data" Then 'check that pivot name exists
For Each pi In pt.PivotFields("Vendor Name").PivotItems
If pi.Name = "BANK OF MARIN" Then 'check that item name exists
pi.Visible = False: Exit For 'Do not show item if it exists
End If
Next pi: Exit For
End If
Next pt