Can't Reconnect Slicers after Changing Data Source

Juglaz

Board Regular
Joined
Jul 2, 2013
Messages
177
Hi all,

I have a workbook with some pivot tables connected to a single slicer. My macro needs to disconnect the pivots from the slicer, change the data source, and reconnect the slicer. When my code gets to reconnecting the slicer it bugs out as if the data source is not the same for all the pivot tables (also doesn't let me reconnect manually). But when I look at the source, it is all the same and correct. If I manually set the data source the slicer reconnects just fine. Why is my code causing problems with the slicer?

Here is my code for setting the data source. Pretty sure this is the code that is causing problems for me.
Code:
newaddress = "$B:$" & Mid(Cells(1, YTDcolumn).Address(), 2, 2)
.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
  PivotCaches.Create(SourceType:=xlDatabase, SourceData:="TOP250Excel!" & newaddress, _
  Version:=xlPivotTableVersion14)

Here is my code for reconnecting the slicer connections.
Code:
ActiveWorkbook.SlicerCaches("Slicer_Top250Excel_cypheren_Query_Name"). _
   PivotTables.AddPivotTable (.PivotTables("PivotTable1"))

I'm way stumped on this one. Help would be much appreciated. Thanks!

-J
 
I have a habit of solving my own problems moments after breaking down and posting here.

Original code looked like this for setting the new source data:
Code:
    .PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:="TOP250Excel!" & newaddress, _
        Version:=xlPivotTableVersion14)
    .PivotTables("PivotTable2").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:="TOP250Excel!" & newaddress, _
        Version:=xlPivotTableVersion14)
    .PivotTables("PivotTable3").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:="TOP250Excel!" & newaddress, _
        Version:=xlPivotTableVersion14)
    .PivotTables("PivotTable4").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:="TOP250Excel!" & newaddress, _
        Version:=xlPivotTableVersion14)

Instead of defining a separate pivot cache for each table, I defined one for the first table and applied it to all:
Code:
    .PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:="TOP250Excel!" & newaddress, _
        Version:=xlPivotTableVersion14)
    .PivotTables("PivotTable2").ChangePivotCache ("PivotTable1")
    .PivotTables("PivotTable3").ChangePivotCache ("PivotTable1")
    .PivotTables("PivotTable4").ChangePivotCache ("PivotTable1")

Now my slicer can connect back up to my pivot tables! \0/
 
Upvote 0

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