I created macro which would refresh all pivot tables in a worksheet. The same code works on one sheet however doesn't on the other. I tried to run it in debug mode and it works fine for first few tables and crush on one in the middle with error:
Run-time error '1004': RefreshTable method of PivotTable class failed.
There are 20 Pivot Tables in this sheet, but on the one where it works are 26. Your help would be much appreciated.
Sub Refresh_Pivots2()
Dim PL As PivotTable
Worksheets("Incidents Pivots").Activate
For Each PL In ActiveSheet.PivotTables
PL.RefreshTable
Next PL
End Sub
I just tried another code
Sub Refresh_Incidents()
Worksheets("Incidents Pivots").Activate
Dim A
A = Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20")
For i = 0 To 19
ActiveSheet.PivotTables(A(i)).RefreshTable
Next i
End Sub
if I start from i=0 it gives an error but when switch it to i=1 it works. Any ideas what is wrong with this table. I am able to refresh it manually.
ActiveSheet.PivotTables(1).SourceData = 'Data Dump'!C1:C14and then refresh the pivot table without error? - Rory