I recorded a macro that applies a top 10 filter to a pivot field in a pivot table. It works well if the pivot table is unfiltered when the macro is run, but if a user hits the button when the top 10 filter is already being applied, I get the:
Run-time error '1004':
Application-defined or object-defined error.
Ideally, if the user selects the macro button and the top 10 filter is already being applied, it would just do nothing...
Here is the macro:
Sub Chart1_Top_10()
'
' Chart1_Top_10 Macro
'
'
Sheets("Chart1").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("SENDER_ID").PivotFilters. _ Add2 Type:=xlTopCount, DataField:=ActiveSheet.PivotTables("PivotTable1"). _
PivotFields("Total Messages"), Value1:=10
Sheets("Dashboard").Select
End Sub
When I debug it highlights the bolded rows above.
Bookmarks