VBA disconnect/connect slicers in active worksheet

Vidar

Well-known Member
Joined
Jul 19, 2012
Messages
1,254
Hi
Sometimes I need to add an extra column to my pivot table by changing the Data Source.
But Excel prompts me to first disconnect my slicers since I have two or more pivottables
on the same worksheet sharing the same pivotcache.

Tried to use the macro recorder to figure out a way to loop through each slicer
and disconnect every pivottable from the slicer.
I'm not familiar with the pivottable/slicer VBA objects.

Vidar
 
Hi Jerry, Thanks for the quick response. Actually I was unaware that when I add an addition column to the source data Table for a formula (which I do all the time as as I build a report), and try to refresh the pivot and slicers, the slicers apparently restrict the pivot table from udating with the new field. So I guess I need to disconnect then re-connect after all. Thanks again. Dave
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Dave, As noted in Post #11 above, the much simpler approach is to use a Named Range Reference (such as a Table, Dynamic Named Range or Static Named Range) as the PivotTable Data Source.

The code that I suggested in Post #19 can be used to convert existing PivotTables to use a Named Range Reference. I wouldn't suggest using that code every time you want to change your data source.
 
Upvote 0
Hi Jerry, I was looking through the posts to see if you already answered this question but did not see it. Is there a way to disconnect multiple slicers in an active sheet or workbook for that matter WITHOUT having to code each individual slicer cache? I can reconnect manually. I find I have multiple slicer cache for various sheets, ex, Slicer_Super_Region21 and Slicer_Super_Region. I also have 50 possible data fields I can add a slicer for, so as I develop the workbook, it would be good to just disconnect all slicers with one click and not have to update code. Thanks. Dave
 
Upvote 0
Hi Dave,

This code should do that...
Code:
Sub DisconnectAllSlicerPivots()
'--disconnects all pivots from all slicerCaches
'    in activeworkbook
'
 Dim pvt As PivotTable
 Dim slc As SlicerCache
    
 For Each slc In ActiveWorkbook.SlicerCaches
   For Each pvt In slc.PivotTables
      slc.PivotTables.RemovePivotTable pvt
   Next pvt
 Next slc
End Sub
 
Upvote 0
Thank you Jerry that works great for the entire workbook. I tried to modify for Active Sheet but can't get that to work. Here is what I used but breaks on the modified line (underlined)
Sub DisconnectAllSlicerPivotsSheet()
'--disconnects all pivots from all slicerCaches
' in activesheet'
Dim pvt As PivotTable
Dim slc As SlicerCache

For Each slc In ActiveWorkbook.ActiveSheet.SlicerCaches
For Each pvt In slc.PivotTables
slc.PivotTables.RemovePivotTable pvt
Next pvt
Next slc
End Sub

Thanks Dave
 
Upvote 0
Dave, I missed your earlier request regarding just handing pivots on the ActiveSheet.

Here's a Sub to do that....

Code:
Sub DisconnectAllSlicerPivotsSheet()
 '--disconnects all pivots in activesheet from all slicerCaches
 ' 
 Dim pvt As PivotTable
 Dim slc As SlicerCache
 
 For Each slc In ActiveWorkbook.SlicerCaches
   For Each pvt In slc.PivotTables
      If pvt.Parent.Name = ActiveSheet.Name Then
         slc.PivotTables.RemovePivotTable pvt
      End If
   Next pvt
 Next slc
End Sub
 
Upvote 0
Hi Jerry, this thread is what I'm looking for. Thanks for your support. I was trying to use the macro at post #39 to disconnect all slicers from my Active Worksheet. However, for some reason it is not disconnecting them. Any ideas?
 
Upvote 0
Hi Dude, Were you trying the code in Post #36 or another post? Post #39 hasn't been written yet, unless you're Dude from the Future! :)

What happens when you try to run the macro?
 
Upvote 0
Can you provide an example workbook with any sensitive data removed/changed?

You could upload it to a hosting site like box.com and post a link, or send me a PM and we'll exchange email addresses.
 
Upvote 0

Forum statistics

Threads
1,217,371
Messages
6,136,167
Members
449,996
Latest member
duraichandra

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