Hi,
i have been trying for quite some time to auto select the slicers based on data validation list.
for example, i have data validation list in the range I7 : I16 and I used INDEX to obtain the respective values based on selection in I7 : I16.
I want slicer to select the values automatically based on the values in cells J7 : J16. I used several codes, but none of them seems to work; not even gives an error message
Here are some codes i used
i have been trying for quite some time to auto select the slicers based on data validation list.
for example, i have data validation list in the range I7 : I16 and I used INDEX to obtain the respective values based on selection in I7 : I16.
I want slicer to select the values automatically based on the values in cells J7 : J16. I used several codes, but none of them seems to work; not even gives an error message
Here are some codes i used
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, cell As Range
Set rng = Range("J7:J16")
Dim slItem As SlicerItem
Application.ScreenUpdating = False
For Each cell In rng
For Each slItem In ThisWorkbook.SlicerCaches("Slicer_Material2").SlicerItems
If slItem.Name = .SlicerItems(cell).Name Then slItem.Selected = True
End If
Next slItem
Next cell
End Sub
Code:
Sub SingleSelection()
Dim si As SlicerItem, fi As SlicerItem
With ActiveWorkbook.SlicerCaches(1)
Set fi = .SlicerItems(CStr(Sheets("SalesOrders").Range("J7:J16")))
fi.Selected = True
For Each si In .VisibleSlicerItems
If si.Name <> fi.Name Then si.Selected = False
Next
End With
End Sub