Hello, I am attempting to write a vba script where the Y-axis of my pivot chart will change based on the slicer that is selected. For instance, when a "completion" slicer is selected I would need the maximum of the axis to be 100 whereas when the "number of pages" slicer is selected I would like the maximum of the Y-axis to change to 50. I was able to identify through the record macro button what the code looks like when a certain slicer is selected:

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

With ActiveWorkbook.SlicerCaches("Slicer_System")
.SlicerItems("Completion").Selected = True
.SlicerItems("number of pages").Selected = False
End With
End Sub

So I've tried writing an if statement after the With..End With statement but I receive an error and it actually crashes out my excel sheet. Here is the sample code:

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

With ActiveWorkbook.SlicerCaches("Slicer_System")
.SlicerItems("Completion").Selected = True
.SlicerItems("number of pages").Selected = False
End With

If .SlicerItems("Completion").Selected = True Then
ActiveChart.Axes(xlValue).MaximumScale = 100
End If


End Sub

Any Suggestions on changing the Y-axis when a different slicer is selected?

Thanks!