There is my code that doesn't compile, the error message is
Next Without For
What can I do ?
Sub CommandButton1_Click()
Dim i As Integer
Dim j As Integer
N = Range(Rows.Count, "A2").End(xlUp).Select
M = Range("B2").End(xlUp).Select
For i = 1 To N
If Cells(i, "A").Value = "2015 Xor 2011" Then
Cells(j, "B").Value = "blue"
Else
If Cells(i, "A").Value = "2001 Xor 2003" Then
Cells(j, "B").Value = "green"
Else
If Cells(i, "A").Value = "2014 Xor 2006" Then
Cells(j, "B").Value = "red"
j = j + 1
End If
Next
End Sub
ElseIf
is not the same asElse
If
And please learn to ident properly :-)
Or use SmartIndenter.
You are missing a couple of End If statements. The correct code should be like this:
You can keep them all in one line as well, also I believe you have other errors, this should fix them up.
many mistackes in your code, even confusing those who answered, so this is it:
this code reads only once the value at the row i
edit : i just noticed: j=i at all times so why bother ?
Instead of starting a new
If
statement each time, you would be best off using theElseIf
statement. Then you only have to use oneEnd If
.