Silvia has attended:
No courses
If and Loops
Can someone see what is wrong with my code.
It keeps saying that "Compile error: Else without If", but i am pretty sure you have to use elseif. Thanks in advance!
Sub Orders()
Range("c5").Select
Do Until ActiveCell = ""
If ActiveCell > 100 Then ActiveCell.Offset(0, 1) = "Empty"
ElseIf ActiveCell > 400 Then ActiveCell.Offset(0, 1) = "Re-order"
Else
ActiveCell.Offset(0, 1).Value = "Full"
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
RE: If and Loops
Hello Silvia,
Thank you for your question. The code is fine, apart from these two lines:
If ActiveCell > 100 Then ActiveCell.Offset(0, 1) = "Empty"
ElseIf ActiveCell > 400 Then ActiveCell.Offset(0, 1) = "Re-order"
They should look like this:
If ActiveCell > 100 Then
ActiveCell.Offset(0, 1) = "Empty"
ElseIf ActiveCell > 400 Then
ActiveCell.Offset(0, 1) = "Re-order"
When you have more than one if statement, e.g. If as well as Elseif or Else, you need to "break" the first line of each statement after "Then".
I'm sure your code will work when you make this change.
Kind regards
Marius Barnard
STL