Hello,

I'm currently using the following code to change which filters are selected in a slicer based on a user input. I know a for loop could be used, but I'm new to VBA and don't know how it would be structured. Only one slicer option will be selected at a time based on the user input. If the slicer item matches the input, then that item should be set to "True" while all other items should be set to "False". If the input does not match the any of the slicer items, I would like to return an error message.

If Sheets("Report Generator").Cells(6, "B").Value = "DynaTen" Then
    With ActiveWorkbook.SlicerCaches("Slicer_Company")
        .SlicerItems("DynaTen").Selected = True
        .SlicerItems("Cummings").Selected = False
        .SlicerItems("BBC").Selected = False
        .SlicerItems("JCI").Selected = False
    End With
End If

If Sheets("Report Generator").Cells(6, "B").Value = "Cummings" Then
    With ActiveWorkbook.SlicerCaches("Slicer_Company")
        .SlicerItems("DynaTen").Selected = False
        .SlicerItems("Cummings").Selected = True
        .SlicerItems("BBC").Selected = False
        .SlicerItems("JCI").Selected = False
    End With
End If

If Sheets("Report Generator").Cells(6, "B").Value = "JCI" Then
    With ActiveWorkbook.SlicerCaches("Slicer_Company")
        .SlicerItems("DynaTen").Selected = False
        .SlicerItems("Cummings").Selected = False
        .SlicerItems("BBC").Selected = False
        .SlicerItems("JCI").Selected = True
    End With
End If

If Sheets("Report Generator").Cells(6, "B").Value = "BBC" Then
    With ActiveWorkbook.SlicerCaches("Slicer_Company")
        .SlicerItems("DynaTen").Selected = False
        .SlicerItems("Cummings").Selected = False
        .SlicerItems("BBC").Selected = True
        .SlicerItems("JCI").Selected = False
    End With
End If
I have tried some previously posted solutions, but none have worked so far.
Thanks for your help