I have a problem relating to updating pivot tables from within vba.
The following works fine when called from a command button:
However when I call the sub from another sub in VBA it results in #Ref! errors in the results:
Are there any subtleties when refreshing data in pivot tables? I have tried adding pt.update to see if this helps but again the puzzling thing is that the same routine works fine when called from a command button but not when calling the sub from another sub.
Any help is much appreciated and thanks for providing such a great forum.
The following works fine when called from a command button:
Code:
Sub RefreshPivotTables()
Dim ws As Worksheet
Dim pt As PivotTable
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
Next pt
Next ws
End Sub
However when I call the sub from another sub in VBA it results in #Ref! errors in the results:
Code:
Call RefreshPivotTables
Are there any subtleties when refreshing data in pivot tables? I have tried adding pt.update to see if this helps but again the puzzling thing is that the same routine works fine when called from a command button but not when calling the sub from another sub.
Any help is much appreciated and thanks for providing such a great forum.