VBA“Compille Error:Else without If”

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

我在VBA中debuggingmacros,我得到这个错误:

“编译错误:否则无If”

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

这是代码的重要部分:

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 

改变你的代码的布局 –

 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 
 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 

这似乎编译得很好

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

 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)** 

如果单元格值小于平均值,则将其突出显示为exception值。 ElseIf Cells(Ind5,Ind6).Value> MeanComp Then Cells(Ind5,Ind6).Interior.Color = RGB(7,253,56) Else End If Next Ind5 Next Ind4