I have tried the following 2 code snippets to refresh a query table
Sheets(“Sheet2”).PivotTables(“PivotTable1”).RefreshTable
Sheets(“Sheet2”).PivotTables(“PivotTable1”).PivotCache.Refresh
Both of them work only if the active cell on Sheet 2 is within the pivottable. If it is not, I get a “Reference is not valid” error.
(In fact there are 2 pivot tables on the sheet, PivotTable2 is a copy of PivotTable1 so both tables update when PivotTable1 is updated).
I guess my questions are:
1) What is the difference between the 2 refresh options
2) Since I am supplying a reference to the object, why does the activecell need to be within it to get a valid reference?
3) Is there a way around this error (apart from selecting the pivot table)?
TIA