I am looking for a way to clear a specific slicer before the code below runs without clearing all slicers in the workbook. The target.address D11, D12, etc are in a table of contents (ultimately there will be about 40 of these), but if the selected slicer isn't cleared and someone clicks on a different cell that uses the same slicer, then it returns a debug message. I am also open to other ways around this issue.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$D$11" Then
Sheets("Trend In Meals").Select
ActiveSheet.PivotTables("PivotTable3").PivotFields ("Meal Occasion")
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Meal Occasion")
.PivotItems("All Occasions - Main Meals and Between Meals").Visible = True
.PivotItems("Total Main Meals").Visible = False
.PivotItems("Breakfast (Includes Brunch)").Visible = False
.PivotItems("Lunch").Visible = False
.PivotItems("Dinner").Visible = False
.PivotItems("Between Meal Occasions").Visible = False
End With
End If
If Target.Address = "$D$12" Then
Sheets("Trend In Meals").Select
ActiveSheet.PivotTables("PivotTable3").PivotFields ("Meal Occasion")
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Meal Occasion")
.PivotItems("All Occasions - Main Meals and Between Meals").Visible = False
.PivotItems("Total Main Meals").Visible = True
.PivotItems("Breakfast (Includes Brunch)").Visible = False
.PivotItems("Lunch").Visible = False
.PivotItems("Dinner").Visible = False
.PivotItems("Between Meal Occasions").Visible = False
End With
End If
Application.EnableEvents = True
End Sub