hallpett
asked on
VBA code; Pivottable refreshes one step behind
Hard to explain this one but I try. On sheet1 I get external acount data from external datasource. On sheet2 I have a pivottable getting data from sheet1. This work fine when I update the sheets manually. But I want it to run by using vba code. My code looks like below:
Sheets("sheet1").Select
ActiveWorkbook.RefreshAll
Sheets("sheet2").Select
Range("B3").Select
ActiveSheet.PivotTables("S aldo").Piv otCache.Re fresh
The problem is that the pivot refreshes with the previous dataset from sheet1. Almost like if I had run the pivot update before updateing data on sheet1. If I run the code a second time without changing parameter then the pivot gets the correct data.
Think this has to be a common problem so I hope someone understand my bad english and can help.
Sheets("sheet1").Select
ActiveWorkbook.RefreshAll
Sheets("sheet2").Select
Range("B3").Select
ActiveSheet.PivotTables("S
The problem is that the pivot refreshes with the previous dataset from sheet1. Almost like if I had run the pivot update before updateing data on sheet1. If I run the code a second time without changing parameter then the pivot gets the correct data.
Think this has to be a common problem so I hope someone understand my bad english and can help.
ASKER
The pause trick does'nt make any difference. I still have to click my "Get data" button twice for the pivot to refresh with the latest data. If I insert a breakpoint on line 5 in your code, and hit F5 when the code stops, then it works. Beats me!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. Would not have found that solution on my own.
may be..
Open in new window
Kris