vendredi 20 avril 2018

If/ElseIf Statements only working for the first if statement

My If (ElseIf) statements seem to only for the first If statement. I'm not sure what I'm missing here. This is for a chart that needs boundaries that change based on the cell values C3:D11. The chart is essentially two overlapping graphs, which is why i have a secondary axes value. Both axes need to change during the IfElse section.

Sub Pyramid()

       Dim cht As Chart
       Set cht = Worksheets("AP-Chart").ChartObjects("Chart 4").Chart
       For Each cell In Range("C3:D11")


        If cell.Value < -15 Then
            cht.Axes(xlCategory).MinimumScale = -20
            cht.Axes(xlValue, xlSecondary).MinimumScale = -20
        ElseIf cell.Value > 15 Then
            cht.Axes(xlCategory).MaximumScale = 20
            cht.Axes(xlValue, xlSecondary).MaximumScale = 20
        ElseIf cell.Value < -20 Then
            cht.Axes(xlCategory).MinimumScale = -30
            cht.Axes(xlValue, xlSecondary).MinimumScale = -30
        ElseIf cell.Value > 20 Then
            cht.Axes(xlCategory).MaximumScale = 30
            cht.Axes(xlValue, xlSecondary).MaximumScale = 30
        ElseIf cell.Value < -30 Then
            cht.Axes(xlCategory).MinimumScale = -40
            cht.Axes(xlValue, xlSecondary).MinimumScale = -40
        ElseIf cell.Value > 30 Then
            cht.Axes(xlCategory).MaximumScale = 40
            cht.Axes(xlValue, xlSecondary).MaximumScale = 40
        ElseIf cell.Value < -40 Then
            cht.Axes(xlCategory).MinimumScale = -50
            cht.Axes(xlValue, xlSecondary).MinimumScale = -50
        ElseIf cell.Value > 40 Then
            cht.Axes(xlCategory).MaximumScale = 50
            cht.Axes(xlValue, xlSecondary).MaximumScale = 50
        End If
       Next cell

       ActiveSheet.ChartObjects("Chart 4").Activate
       ActiveChart.ChartArea.Select
       myPDF = "\\stchsfs\arboari$\Profile-Data\Desktop\Export Trial1\c1-" & Sheets("AP").Range("C" & i + 3).Value2 & ".pdf"
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=myPDF, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    i = i + 1
     Next counter

End Sub

Thanks!

Aucun commentaire:

Enregistrer un commentaire