wb.Sheets.Add Before:=Worksheets("Data")
ActiveSheet.Name = "PD"
Set ws = Sheets("PD")
ws.Select
wb.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Data", Version:=xlPivotTableVersion10).CreatePivotTable TableDestination:= _
"PD!R1C1", TableName:="PD Exceptions", DefaultVersion:=xlPivotTableVersion12
Set pt = ws.PivotTables("PD Exceptions")
With pt.PivotFields("Transaction Method")
.Orientation = xlPageField
.Position = 1
.PivotItems("NSF").Visible = False
End With
With pt.PivotFields("Account Number")
.Orientation = xlRowField
.Position = 1
.Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
End With
With pt.PivotFields("Product")
.Orientation = xlRowField
.Position = 2
.Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
End With
With pt.PivotFields("Posting Dt")
.Orientation = xlRowField
.Position = 3
.Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
End With
pt.AddDataField pt.PivotFields("Posting Amt"), "Posting Amt.", xlSum
pt.AddDataField pt.PivotFields("Deposit Amt"), "Deposit Amt.", xlSum
pt.CalculatedFields.Add "PDEx", "='Posting Amt' -'Deposit Amt'", True
With pt.PivotFields("PDEx")
.Orientation = xlDataField
.Caption = "Variance"
End With
With ActiveSheet.PivotTables("PD Exceptions").DataPivotField
.Orientation = xlColumnField
.Position = 1
End With
pt.RefreshTable
pt.PivotFields("Account Number").PivotFilters.Add Type:=xlValueIsGreaterThan, DataField:=pt.PivotFields("Variance"), Value1:=0
pt.PivotFields("Posting Dt").PivotFilters.Add Type:=xlValueIsGreaterThan, DataField:=pt.PivotFields("Variance"), Value1:=0
The code breaks when it gets to the last 2 lines (in Red) because the pivot table does not show the filter options to filter by "Greater Than", in fact it only shows the option to use the Top 10 and nothing else. Here is a screenshot attached.
Bookmarks