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!
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!