Pivot Table Update - Problem

Sloopy

New Member
Joined
May 24, 2010
Messages
15
I have a problem relating to updating pivot tables from within vba.

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.
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Watch MrExcel Video

Forum statistics

Threads
1,114,366
Messages
5,547,486
Members
410,797
Latest member
mlfuson
Top