Refresh Pivot same time as ODBC refresh

dibblejon

New Member
Joined
Sep 23, 2010
Messages
37
Hi

I have a spreadsheet connected to our in house system via ODBC. When I refresh sheet2(data) I need sheet1(summary) - which is a pivot table using the data from sheet2(data) to update as well.

Any help on how I could achieve would be great.

Many thanks

Jon D
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Apologies I should of been clearer.

When I hit the "refresh all" button the table connected via ODBC refreshes but the pivot table does not.
 
Upvote 0
In that case it may be better to use a bit of VBA code:

Code:
Sub RefreshAllInOrder()
    Dim oQT As QueryTable
    Dim oPc As PivotCache
    Dim oSh As Worksheet
    For Each oSh In Worksheets
        For Each oQT In oSh.QueryTables
            oQT.Refresh False
        Next
    Next
    For Each oPc In ActiveWorkbook.PivotCaches
        oPc.Refresh
    Next
End Sub
 
Upvote 0
Thanks - I am a complete VBA newbie though!

Where would I need to add the references to my sheets?

Does this get declared in the General or as a Private Sub?

Sorry.
 
Upvote 0
The code refreshes all queries and pivot tables of the active workbook.
Alt+F11 to go to the VBA editor, Insert, Module to insert a module, paste in this code.
Alt+F8 from Excel gives you the list of macros, select thisone and click run. ALternatively, add a Forms button to a sheet and assign this macro to it.
 
Upvote 0
Thank you very much for your help.

I have done as you advised but when I run the macro nothing happens.

My "Data" table uses parameters when refreshing - would this cause the macro to not run?
 
Upvote 0
You can step through the code by putting your cursor inside the code block and hitting F8 - then keep hitting F8 to execute one line at a time. This should show you what the code is doing (as described here) and whether the refresh commands are being executed.

Not sure but for Excel 2007 or 2010 you might need different syntax for query tables (as members of the list object collection).

Untested excel 2007/2010 code below. I suppose it could error if there are listobjects without query tables ...
Code:
Public Sub foo()
Dim ws As Worksheet
Dim lo As ListObject
Dim qt As QueryTable
Dim pc As PivotCache

For Each ws In ThisWorkbook.Worksheets
    For Each lo In ws.ListObjects
         lo.QueryTable.Refresh False
    Next lo
Next ws

For Each pc In ActiveWorkbook.PivotCaches
    pc.Refresh
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top