VBA“编译错误:没有If的其他”

时间:2015-06-17 12:28:35

标签: excel vba excel-vba debugging

到目前为止,没有人的“解决方案”修复我的错误,任何提示?

我正在调试VBA中的宏,我收到此错误:

“编译错误: 否则没有“

有关如何解决此问题的任何提示?

以下是代码的重要部分:

For Ind4 = 1 To iPlateNo
    Ind6 = Ind4 + 2
    MeanComp = 0.6 * Cells(81, Ind6).Value
    For Ind5 = 1 To iMxRNo
        If Cells(Ind5, Ind6).Value < MeanComp Then Cells(Ind5, Ind6).Interior.Color = RGB(255, 0, 0)
'           If the cell value is less than the average highlight them red as outliers. (More likely: from pipettes that didn't release)
        ElseIf Cells(Ind5, Ind6).Value > MeanComp Then Cells(Ind5, Ind6).Interior.Color = RGB(7, 253, 56)
'           If the cell value is greater than the average highlight them green as outliers. (Unlikely unless )
        Else
        End If
    Next Ind5
Next Ind4

3 个答案:

答案 0 :(得分:2)

更改代码的布局 -

For Ind4 = 1 To iPlateNo
    Ind6 = Ind4 + 2
    MeanComp = 0.6 * Cells(81, Ind6).Value
    For Ind5 = 1 To iMxRNo
        If Cells(Ind5, Ind6).Value < MeanComp Then
        Cells(Ind5, Ind6).Interior.Color = RGB(255, 0, 0)
'           If the cell value is less than the average highlight them red as outliers. (More likely: from pipettes that didn't release)
        ElseIf Cells(Ind5, Ind6).Value > MeanComp Then
        Cells(Ind5, Ind6).Interior.Color = RGB(7, 253, 56)
'           If the cell value is greater than the average highlight them green as outliers. (Unlikely unless )

        End If
    Next Ind5
Next Ind4

答案 1 :(得分:1)

For Ind4 = 1 To iPlateNo
    Ind6 = Ind4 + 2
    MeanComp = 0.6 * Cells(81, Ind6).Value
    For Ind5 = 1 To iMxRNo
        If Cells(Ind5, Ind6).Value < MeanComp Then
            Cells(Ind5, Ind6).Interior.Color = RGB(255, 0, 0)
        ElseIf Cells(Ind5, Ind6).Value > MeanComp Then
            Cells(Ind5, Ind6).Interior.Color = RGB(7, 253, 56)
        End If
    Next Ind5
Next Ind4

这似乎编译得很好

编辑:删除代码周围的子程序

答案 2 :(得分:0)

You just need to make the small change in the code that put the statement 
after then in the next line shown in the below code highlighted as bold.
For Ind4 = 1 To iPlateNo
Ind6 = Ind4 + 2
MeanComp = 0.6 * Cells(81, Ind6).Value
For Ind5 = 1 To iMxRNo
If Cells(Ind5, Ind6).Value < MeanComp **Then
Cells(Ind5, Ind6).Interior.Color = RGB(255, 0, 0)**

'如果单元格值小于平均值,则将其红色显示为异常值。     ElseIf Cells(Ind5,Ind6).Value&gt; MeanComp 然后     细胞(Ind5,Ind6).Interior.Color = RGB(7,253,56)     其他     万一     下一个Ind5     下一个Ind4