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
 
Dave,

The SlicerCache.ClearAllFilters method was added in Excel 2013. So if you have Excel 2010 you would need to use .ClearManualFilter instead.

I'm not sure there's a functional difference. When I chose to use .ClearAllFilters, I assumed that would be better because it would also clear any filters that were applied using criteria based filters like CustomerName "Begins with" "B" instead of manual checkboxes or slicers.

In testing, .ClearManualFilter appears to clear criteria based filters as well.

The other code example you found looks fine- they are similar in approach with a few variations.
Exiting the For loop when a match is found on a worksheet is good idea that I hadn't considered.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi, your piece of code to refresh the source of PivotTables with connected slicers is excellent!
I did build it into my Dashboard solution with a little modification: instead of setting fixed slicer names in the code I'm running a loop through all Slicer Caches and assign the names automatically (in my peticular case I have 29 slicers):

Code:
Dim vSlicerList(1 To 29) As Variant
Dim oSlicercache As SlicerCache

'--fill list of slicers.
    For Each oSlicercache In ActiveWorkbook.SlicerCaches
      vSlicerList(oSlicercache.Index) = oSlicercache.Name
    Next

Now I did run into troubles: I promise, last week, the code WAS working fine, but this week I get the error message:
"1004: Application defined or object-defined error".

A trace revealed, that the error happens on the following line of the original code, which is within the loop to store the current slicer connections:
Code:
            '--Disconnect from Slicer
            .PivotTables.RemovePivotTable (PT)

I did setup a separate workbook with a dummy pivot table and connected slicers. There again, the code is working :-O
Don't know, where to look next and hope you can give some directions for further investigations.
Thanks in advance,
Frank
 
Upvote 0
Hi Jerry,

I followed the whole post and I found some good tips for my problem, however my situation is slightly different.

I need to disconnect my slicers, pick some choices from the slicers, and then reconnect the slicers back to the same pivots but then by reconnecting I refresh my pivots based on the options (choices) I selected when slicers were OFF.

Can you help me to do that? I have two separate buttons for each action OFF and ON.

Thanks in advance.

AM
 
Upvote 0
Jerry, forgive my ignorance but this code almost works for me. I have 5 slicers connected to my pivot tables and am trying to assign a macro button to disconnect all slicers from pivots. That said, I have some questions about your code:

What does the "Dim i As Long" statement mean?
Do I have to assign another letter other than "i" to the other slicers?
What does "For i = .Count To 1 Step -1 .RemovePivotTable (.Item(i)) Next i" mean?
 
Upvote 0

Forum statistics

Threads
1,217,367
Messages
6,136,146
Members
449,994
Latest member
Rocky Mountain High

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