Update Source Data for Pivot Table

Mayanwolfe

New Member
Joined
Jun 5, 2013
Messages
21
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!
 

Mayanwolfe

New Member
Joined
Jun 5, 2013
Messages
21
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!
 

Forum statistics

Threads
1,081,417
Messages
5,358,553
Members
400,503
Latest member
RedSquirrel

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top