我正在使用以下 VBA Else-If代码:
If ActiveSheet.Range(range_name).Value < "8.50%" Then
ActiveSheet.Shapes.Range(Array(shape_name)).Select
With Selection.ShapeRange.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(192, 0, 0)
.Transparency = 0
.Solid
End With
ElseIf ActiveSheet.Range(range_name).Value < "9.70%" Then
ActiveSheet.Shapes.Range(Array(shape_name)).Select
With Selection.ShapeRange.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 255, 0)
.Transparency = 0
.Solid
Else
ActiveSheet.Shapes.Range(Array(shape_name)).Select
With Selection.ShapeRange.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 255, 0)
.Transparency = 0
.Solid
End With
当我运行它时,我收到一个错误:“Else without If”。因此,我将Else行更改为:
ElseIf ActiveSheet.Range(range_name).Value >= "9.70%" Then
但是,它仍然给我同样的错误,即使这个Else有一个If
这是为什么?第一个代码也是正确的,一开始就不应该出错。那么为什么会这样呢?提前致谢!