Update Source Data for Pivot Table

Mayanwolfe

New Member
Joined
Jun 5, 2013
Messages
27
Hi all! I have a workbook that contains a pivot table, a data set, and several user input pages. I have a macro that updates this data set, and the size of the set may change between each update based on user inputs elsewhere in the workbook.

I would like the Pivot Table to update as well, without re-creating it. Essentially, the data set would update, and the pivot table would recognize the new range size as the Data Source, then the Pivot Table would refresh to incorporate this data. I understand that I would have to redefine the pivot cache, but I'm not sure how to do this without rebuilding the table.

Here is the code for building my current table's cache. How do I modify this to just update it instead of resetting the table?

Set PSheet = Worksheets("PivotTable")
Set DSheet = Worksheets("Data Set")

'Define Data Range
LastRow = DSheet.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = DSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Set PRange = DSheet.Cells(1, 1).Resize(LastRow, LastCol)

'Define Pivot Cache
Set PCache = ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:=PRange). _
CreatePivotTable(TableDestination:=PSheet.Cells(5, 2), _
TableName:="AnalystSummaryData")

Thanks for any assistance!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Still looking for any assistance on this - I'm looking to understand how to update a pivot table's range and cache without re-creating the table from scratch. Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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