Last update on October 14, 2011 - I know more info now, so I will summarize everything here and delete all my previous descriptions/questions.
The problem is, after running a certain program, I get some weird error. It's similar to, but not exactly like, when I click "Split". The difference is the solid gray bars do not show up. It's sort of weird. More recently, I have started thinking it is probably caused by the field list of the pivot tables involved.
The problem occurs with any of the three following pieces of code
Code 1
Dim pvtCache As PivotCache
For Each pvtCache In ThisWorkbook.PivotCaches
pvtCache.Refresh
Next pvtCache
Code 2
ThisWorkbook.RefreshAll
Code 3
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
But not with this, where the only difference is I added ws.Activate to Code 3
Code 4
Dim ws As Worksheet
Dim pt As PivotTable
For Each ws In ThisWorkbook.Worksheets
ws.Activate
For Each pt In ws.PivotTables
pt.RefreshTable
Next pt
Next ws
So, my question is, can any one explain this? Can any one fix Code 1 (which is much faster in a spreadsheet with 2 pivot caches from large data sources, but 46 pivot tables) to make it work without this error?
Thanks for any help!!!
I have multiple pivots from multiple sheets and all three code snippets works fine. There should be something else causing the problem, its not the code.
Your code snippets run correctly.
It could be that the screen display may not be refreshing after your code is run.
Try adding this round your code:
Application.ScreenUpdating = False
''//Your code here
DoEvents
Application.ScreenUpdating = True
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.