Reset slicer selection based on cell input

Molecheese

New Member
Joined
Jan 30, 2016
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi - I have a data slicer which I want to change based on the input to an individual cell (C1). The below code is doing that, but it leaves the previously selected option in the slicer too - what code do I need to add to 'reset' the values or deselect any other selected slicer options before selecting the new value. Apologies if this question is boring / simple - I'm very much a self-taught novice. Thanks in advance

Private Sub Worksheet_Change(ByVal Target As Range)
Dim sc As SlicerCache
Dim si As SlicerItem
Set sc = ThisWorkbook.SlicerCaches("Slicer_Hole")
If Not Intersect(Target, [c1]) Is Nothing Then
If Target.Value = "(ALL)" Then
sc.ClearAllFilters
Else
For Each si In sc.SlicerItems
If Target.Value = si.Name Then
si.Selected = True
Else
si.Selected = False
End If
Next
End If
End If
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim sc As SlicerCache
    Dim si As SlicerItem
    Set sc = ThisWorkbook.SlicerCaches("Slicer_Hole")
    If Target.Address = "$C$1" Then
        If Target.Value = "(ALL)" Then
            sc.ClearAllFilters
        Else
            sc.ClearManualFilter
            For Each si In sc.SlicerItems
                If Target.Value <> si.Name Then si.Selected = False
            Next
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,500
Messages
6,131,015
Members
449,615
Latest member
Nic0la

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