I would like to select the two first values of a slicer using VBA.
For now, my code is as follow:
ActiveSheet.SlicerCaches("EXAMPLE").ClearAllFilters
cnt = .SlicerItems.Count
If cnt > 2 Then
For i = 3 To cnt
.SlicerItems(i).Selected = False
Next
End If
End With
Could you please help me on that ?
Thank you
>Solution :
Assuming the Slicer is in the ActiveWorkbook (replace ActiveWorkbook with a reference to the specific Workbook otherwise) and the Slicer is named "EXAMPLE", then use:
Dim i As Long
With ActiveWorkbook.SlicerCaches("EXAMPLE")
.ClearAllFilters
For i = 1 To .SlicerItems.Count
.SlicerItems(i).Selected = i <= 2
Next i
End With