VBA Created Pivot Table needs manual refresh

KG Old Wolf

Board Regular
Joined
Sep 20, 2009
Messages
65
Following is a sub procedure that proudces the desired pivot table just fine if I step through its execution using "F8", if I use "F5" it shows none of the detail.

What's really odd is that the detail is there... I look at the filter carot and the fields are populated but they just don't appear - it looks like a blank pivot table. I hit "refresh" and all data then appears. Again, it works just fine in step mode.

I even inserted "ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh" in the macro and it still requires a manual "refresh"

Anyone see what I am clearly missing?

Thanks for the advice,
KG Old Wolf
--------------------------------------------------------
'
Sub CreatePivot()
'
Dim WSD As Worksheet
Dim PTCache As PivotCache
Dim PT As PivotTable
Dim PRange As Range
Dim FinalRow As Long
Dim FinalCol As Long
'
Set WSD = Worksheets("RVU Output")
'
'
' Delete Any Prior Pivot Tables
'
For Each PT In WSD.PivotTables
PT.TableRange2.Clear
Next PT
'
'
' Define Input Area and Set Up a Pivot Cache
'
FinalRow = WSD.Cells(Application.Rows.Count, 1).End(xlUp).Row
FinalCol = WSD.Cells(1, Application.Columns.Count).End(xlToLeft).Column
'
Set PRange = WSD.Cells(1, 1).Resize(FinalRow, FinalCol)
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:= _
xlDatabase, SourceData:=PRange.Address)
'
'
' Create the Pivot Table from the Pivot Cache
'
Set PT = PTCache.CreatePivotTable(TableDestination:=WSD. _
Cells(1, FinalCol + 2), TableName:="PivotTable1")
'
'
' Turn Off Updating While Building the Table
'
PT.ManualUpdate = True
'
'
' Set Up the Row and Column Fields
'
PT.AddFields RowFields:="MD Name", ColumnFields:="Location Abbr."
'
'
' Set Up the Data Fields
'
With PT.PivotFields("YTD RVU Extended")
.Orientation = xlDataField
.Function = xlSum
.Position = 1
End With
'
'
' Calculate the Pivot Table
'
PT.ManualUpdate = False
PT.ManualUpdate = True
'
'
' Format the Pivot Table
'
PT.ShowTableStyleRowStripes = True
PT.TableStyle2 = "PivotStyleMedium10"
'
'
' Display Results
'
WSD.Activate
Range("J2").Select
'
'
'
End Sub
---------------------------------------------------
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Same problem here as well. The problem seems to come up for a number of people fairly regularly. Has anyone found a solution?
 
Upvote 0
I figured it out. The ".Refresh" and ".RefreshTable" methods only refresh the cache with source data. You need to use the ".Update" method to update the pivot table on the worksheet.

So something like:

ActiveSheet.PivotTables(1).Update

Cheers!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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