Solved

Excel Macro Pivot Table

Posted on 2016-07-21
4
45 Views
Last Modified: 2016-07-22
I have a spreadsheet with two tabs.
Tab 1 is a Pivot table of Tab 2
Tab 2 is created via a connection through ODBC

I have a macro that request to refresh all but the summary pivot table is being refreshed first so it does not reflect the details which have not yet been refreshed.  The details then are refreshed and accurate but the pivot table is not.

By refreshing again, the pivot table does reflect the details that are now accurate.

Does anyone know how to address this?
0
Comment
Question by:Joe M
4 Comments
 
LVL 7

Expert Comment

by:tomfarrar
ID: 41723474
If I understand what you said, it sounds like the macro is "refreshing all" pivot tables before the ODBC is updated.  The order of execution should be reversed.  I believe the "refresh all" command is probably only related to all the pivot tables and not the raw data from the ODBC.  That would be my guess.
1
 
LVL 28

Assisted Solution

by:Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj) earned 250 total points
ID: 41723509
Make sure you use the following line of code before the code which refreshes the pivot table.

Tab2.querytables(1).refresh backgroundquery:=false

See if that resolves your issue.
1
 
LVL 16

Accepted Solution

by:
Jerry Paladino earned 250 total points
ID: 41723786
The behavior your experiencing is typical when"Refresh All" is used in a macro.   Refresh All does update all the connections and the pivot tables but the timing is rarely consistent where the ODBC connection will be executed before the Pivot Table that relies on it.

If your code uses an "ActiveWorkbook.RefreshAll" command, I would suggest that you replace it with the code that Neeraj suggested above to specifically update the ODBC connection and then use the code below after that to update the Pivot Tables.
 Dim pc As PivotCache
    For Each pc In ActiveWorkbook.PivotCaches
      pc.Refresh
    Next pc

Open in new window

1
 

Author Closing Comment

by:Joe M
ID: 41725127
Thank you everyone for your help
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now