Start a macro when changing a value for Slicer

jack10063

Board Regular
Joined
Aug 12, 2008
Messages
103
Hi,

I'd like to start a macro every time a value is changed in a Slicer. Any ideas how to do this??

Br,
Jack
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I don't think you can specifically. If you assign a macro to the slicer, it stops working as a slicer, and there are no events associated with slicers. Nearest thing I can think of would be the worksheet's PivotTableUpdate event and store the old value of the relevant field in a variable which you check each time the table updates.
 
Upvote 0
Rorya,

Thanks for your answer. I am trying to use PivotTableUpdate as you suggest:

Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
On Error Resume Next
If ActiveSlicer.Name = "slicer_1" Then
 '   MsgBox "test"
End If
 
End Sub

So, I would like to start the macro only if the active Slicer is "slicer_1". Unfortunately, I am getting a compile error saying: "argument not optional". Thus, it seems that I cannot use "ActiveSlicer.Name". How could I get the name for the active Slicer??

Br,
Jack
 
Upvote 0
Hi,

I'd like to start a macro every time a value is changed in a Slicer. Any ideas how to do this??

Br,
Jack

This works for me, mileage may vary. This depends on the fact that a slicer operates on one or more pivottables, and you can trap changes to ANY pivottable using Workbook_SheetPivotTableChangeSync.

Add a macro like this:

Code:
Private Sub Workbook_SheetPivotTableChangeSync(ByVal Sh As Object, ByVal Target As PivotTable)
    changeForecastHeader
End Sub

changeForecastHeader is my macro to change my chart header to insert the slicer details, replace this with a call to your own macro.
 
Upvote 0
Hi Guys,

I have applied a slicer to a data table, and i dont want user to "clear filters" on the slicers.
The user can only able to use the buttons in the slicers, but the "clear filters" should be disabled, please help me how it can be done by any way.
 
Upvote 0
I found a Workaround for this issue

1- Create an ID for the Table, the ID should be calculated automatically (something like =ROW(Any column in the table)
2- With another sheet or the same sheet use SMALL Function with SUBTOTAL function to extract the ID of the filter. Subtotal Let you work only with the filtered values, in your case only one value.
3- Create a Worksheet_Calculate() event to track when the cell with formula change and add the macro there.

Here is a short video showing how I did it.

I hope this helps
https://www.dropbox.com/s/gx4wqkqcnp6eim9/Slicer Macro Demo.webm?dl=0
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,973
Members
448,933
Latest member
Bluedbw

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