1

So far nobody's "solution" fixes my bug, any tips?

I'm debugging a macro in VBA and I get this error:

"Compile error: Else without If"

Any tips on how to fix this?

Here is the important portion of the code:

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
2
  • 3
    remove the last else: it is unuseful for the current code Commented Jun 17, 2015 at 12:32
  • @moffeltje thanks, I don't see what Next Ind5 was supposed to line up with, but I still have the error message. Commented Jun 17, 2015 at 12:36

3 Answers 3

1

Change the layout of your code -

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
Sign up to request clarification or add additional context in comments.

6 Comments

That does seem to compile fine, but then I get this error message: "Run-time error '438': Object doesn't support this property or method". Is this related to this problem?
I don't know the rest of your code. Where does error 438 occur?
on a line with "Application.CalculationxlManual" near the start of my macro.
That's really broad and very difficult to diagnose without the rest of the code.
@ThomasShera if one of the answers has solved your question, please click the green checkmark next to it to mark the question as answered.
|
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

This seems to compile just fine

edit: removed sub procedure around code

3 Comments

That does seem to compile fine, but then I get this error message: "Run-time error '438': Object doesn't support this property or method". Is this related to this problem?
I am running this in a larger macro, so I got rid of the Private Sub line and the End Sub line and inserted it.
Ya sorry, I put it in an editor and needed to add the sub
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)**

' If the cell value is less than the average highlight them red as outliers. ElseIf Cells(Ind5, Ind6).Value > MeanComp Then Cells(Ind5, Ind6).Interior.Color = RGB(7, 253, 56) Else End If Next Ind5 Next Ind4

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.