MrDavidThorn
asked on
Pivot tables not refreshing by VBA
Im using the below vba code - to resfresh all pivots
Sub refreshpivot()
For ishtCount = 1 To Sheets.Count
For ipiv = 1 To Sheets(ishtCount).PivotTab les.Count
Application.Wait Now() + TimeValue("00:00:01")
If Sheets(ishtCount).PivotTab les(ipiv). Name <> "RETAIL Book" Then
Sheets(ishtCount).PivotTab les(ipiv). RefreshTab le
End If
DoEvents
Next ipiv
Next ishtCount
Application.Calculate
MsgBox "Done"
End Sub
Works fine sometimes other times I get the error message Run-time error '1004'
Refresh tabke method of PivotTable class failed.
Sub refreshpivot()
For ishtCount = 1 To Sheets.Count
For ipiv = 1 To Sheets(ishtCount).PivotTab
Application.Wait Now() + TimeValue("00:00:01")
If Sheets(ishtCount).PivotTab
Sheets(ishtCount).PivotTab
End If
DoEvents
Next ipiv
Next ishtCount
Application.Calculate
MsgBox "Done"
End Sub
Works fine sometimes other times I get the error message Run-time error '1004'
Refresh tabke method of PivotTable class failed.
Or try this different approach:
jppinto
Sub refreshpivot()
Dim pt As PivotTable
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Application.Wait Now() + TimeValue("00:00:01")
For Each pt In ws.PivotTables
If pt.Name <> "RETAIL Book" Then
pt.RefreshTable
End If
Next pt
Next ws
Application.Calculate
MsgBox "Done"
End Sub
jppinto
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sheets(ishtCount).PivotTab
try like this:
Sheets(ishtCount).PivotTab
jppinto