I have a Pivot Table that's source is a table called "Data". In my code, I convert this table to a range, perform a variety of functions, then convert it back to a table with the same name ("Data"). I want the code to automatically update the source data of the Pivot Table to the new "Data" table range, and then refresh the pivot. Here's the code I have right now which is NOT working:
Any help would be greatly appreciated!
Thanks!
Code:
Sub PivotTable()
Dim PivotSheet as Worksheet
ActiveWorkbook.PivotTables("PivotTable2").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:=DataSheet.ListObjects("Data"),
Version:=xlPivotTableVersion14)
PivotSheet.PivotTable2.RefreshTable
End Sub
Any help would be greatly appreciated!
Thanks!