【发布时间】:2018-10-01 12:12:09
【问题描述】:
我的 If (ElseIf) 语句似乎只针对第一个 If 语句。我不确定我在这里缺少什么。这适用于需要根据单元格值 C3:D11 更改边界的图表。该图表本质上是两个重叠的图表,这就是为什么我有一个辅助轴值。在 IfElse 部分中,两个轴都需要更改。
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
谢谢!
【问题讨论】:
-
考虑
Select Case,您可以在其中使用Case -20 to -15样式语句来描述范围。if ... elseif语句可能会令人困惑且难以维护(正如您刚刚发现的那样!)
标签: vba loops if-statement charts