ADSkinner072
New Member
- Joined
- Jun 2, 2021
- Messages
- 3
- Office Version
- 2016
- Platform
- Windows
Good morning,
I have a sheet I am working on that has slicers and pivot tables that will refresh daily on new data from a newly created table. The code below is what I am using to create my new sheet as a table and name it as "Data", remove the connections to the slicers, and then changing the data source on the pivot tables to look at the Data source "Data"
The problem I am having is when I go back to reconnect the slicers, as none of my pivot tables are listed as options to reconnect. Is there an easier way or better way I could be doing this sequence?
Thank you very much for your time
I have a sheet I am working on that has slicers and pivot tables that will refresh daily on new data from a newly created table. The code below is what I am using to create my new sheet as a table and name it as "Data", remove the connections to the slicers, and then changing the data source on the pivot tables to look at the Data source "Data"
The problem I am having is when I go back to reconnect the slicers, as none of my pivot tables are listed as options to reconnect. Is there an easier way or better way I could be doing this sequence?
Thank you very much for your time
VBA Code:
lRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
lCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
ActiveSheet.ListObjects.Add(xlSrcRange, Range(Cells(1, 1), Cells(lRow, lCol)), , xlYes).Name = "Data"
Sheets("Team Performance").Select
ActiveSheet.Shapes.Range(Array("New/Open")).Select
ActiveWorkbook.SlicerCaches("Slicer_New_Open").PivotTables.RemovePivotTable ( _
ActiveSheet.PivotTables("PivotTable4"))
ActiveWorkbook.SlicerCaches("Slicer_New_Open").PivotTables.RemovePivotTable ( _
ActiveSheet.PivotTables("PivotTable6"))
ActiveWorkbook.SlicerCaches("Slicer_New_Open").PivotTables.RemovePivotTable ( _
ActiveSheet.PivotTables("PivotTable7"))
ActiveWorkbook.SlicerCaches("Slicer_New_Open").PivotTables.RemovePivotTable ( _
ActiveSheet.PivotTables("PivotTable8"))
ActiveSheet.Shapes.Range(Array("OrderedByGroup")).Select
ActiveWorkbook.SlicerCaches("Slicer_OrderedByGroup").PivotTables. _
RemovePivotTable (ActiveSheet.PivotTables("PivotTable4"))
ActiveWorkbook.SlicerCaches("Slicer_OrderedByGroup").PivotTables. _
RemovePivotTable (ActiveSheet.PivotTables("PivotTable5"))
ActiveWorkbook.SlicerCaches("Slicer_OrderedByGroup").PivotTables. _
RemovePivotTable (ActiveSheet.PivotTables("PivotTable6"))
ActiveWorkbook.SlicerCaches("Slicer_OrderedByGroup").PivotTables. _
RemovePivotTable (ActiveSheet.PivotTables("PivotTable7"))
ActiveWorkbook.SlicerCaches("Slicer_OrderedByGroup").PivotTables. _
RemovePivotTable (ActiveSheet.PivotTables("PivotTable8"))
ActiveSheet.Shapes.Range(Array("Product Code 1")).Select
ActiveWorkbook.SlicerCaches("Slicer_Product_Code1").PivotTables. _
RemovePivotTable (ActiveSheet.PivotTables("PivotTable4"))
ActiveWorkbook.SlicerCaches("Slicer_Product_Code1").PivotTables. _
RemovePivotTable (ActiveSheet.PivotTables("PivotTable5"))
ActiveWorkbook.SlicerCaches("Slicer_Product_Code1").PivotTables. _
RemovePivotTable (ActiveSheet.PivotTables("PivotTable6"))
ActiveWorkbook.SlicerCaches("Slicer_Product_Code1").PivotTables. _
RemovePivotTable (ActiveSheet.PivotTables("PivotTable7"))
ActiveWorkbook.SlicerCaches("Slicer_Product_Code1").PivotTables. _
RemovePivotTable (ActiveSheet.PivotTables("PivotTable8"))
ActiveSheet.Shapes.Range(Array("Warehouse")).Select
ActiveWorkbook.SlicerCaches("Slicer_Warehouse").PivotTables.RemovePivotTable ( _
ActiveSheet.PivotTables("PivotTable4"))
ActiveWorkbook.SlicerCaches("Slicer_Warehouse").PivotTables.RemovePivotTable ( _
ActiveSheet.PivotTables("PivotTable5"))
ActiveWorkbook.SlicerCaches("Slicer_Warehouse").PivotTables.RemovePivotTable ( _
ActiveSheet.PivotTables("PivotTable6"))
ActiveWorkbook.SlicerCaches("Slicer_Warehouse").PivotTables.RemovePivotTable ( _
ActiveSheet.PivotTables("PivotTable7"))
ActiveWorkbook.SlicerCaches("Slicer_Warehouse").PivotTables.RemovePivotTable ( _
ActiveSheet.PivotTables("PivotTable8"))
VBA Code:
Dim pt As PivotTable
For Each pt In ActiveWorkbook.Worksheets("Team Performance").PivotTables
pt.ChangePivotCache ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:="Data")
Next pt