I am looking for your assistance with the following error.
I have some VBA code that opens a workbook and copies in a sheet containing a pivot table.
The code then selects the pivot table, filters by date, and copies some fields out.
This functionality works perfectly on first time use. However, when this report is used more than once in a day, it hits the following error:
The issue is with the assignment of the Pivot table name, as the VBA just uses system defaults. The code is as follows:
Sheets("Sheet1").Select
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveSheet.PivotTables("PivotTable1").PivotFields("Date ").AutoSort _
xlDescending, "Date "
Is there an alternative way dynamically select the pivot table regardless of name?
Alternatively, is there code to clear the history at the end of execution so that every time the report is run it will be pivot 1?
Any help would be greatly appreciated.
Thanks in advance