?
Solved

Excel Macro Pivot Table

Posted on 2016-07-21
4
Medium Priority
?
56 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 33

Assisted Solution

by:Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj) earned 1000 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 1000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

649 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