Refresh Pivot Tables

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
612
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I run a userform that submits data to a database and then comes back to the current workbook and should update the 2 pivot tables I have in my workbook.
The code below refreshes the 1st table but doesn't refresh the 2nd one. I have tried this with and without the second "ActiveWorkbook.Connections("ReportsTabPivot").Refresh" and it doesn't refresh. I have to right click and refresh for this table to update.

Any ideas how I can rectify this to auto refresh like the 1st table?

Code:
'Refreshes data links so pivot tables can update 1st Table
    ActiveWorkbook.Connections("ReportsTabPivot").Refresh
    'refreshes Pivot Table
    Worksheets("Reports").Select
        ThisWorkbook.RefreshAll
'Refreshes data links so pivot tables can update 2nd Table
    Worksheets("Raise").Select
    ActiveWorkbook.Connections("ReportsTabPivot").Refresh
        Range("E24").Select
        ActiveWorkbook.RefreshAll

thanks
Gavin
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

rondeondo

Board Regular
Joined
Aug 15, 2012
Messages
156
Hi Gavin

I wrote a macro for refreshing all of the pivot tables in all of the sheets of a workbook

VBA Code:
Public Sub PivotRefresh()
'refresh all the pivot tables within a workbook
Dim pt As PivotTable
Dim pc As PivotCache

For Each pc In ActiveWorkbook.PivotCaches
  On Error Resume Next
  pc.Refresh
Next pc

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,114,520
Messages
5,548,529
Members
410,845
Latest member
OldSwimmer1650
Top