Hello again,
I am just starting VBA and trying to practice loops.
Can you please help me understand why this code works:
But if I were to change my code to this it will not:
Thanks
JV
I am just starting VBA and trying to practice loops.
Can you please help me understand why this code works:
Code:
For startingnumber = 1 To endingnumber
If startingnumber = 1 Or startingnumber = 3 Or startingnumber = 5 Or startingnumber = 7 Or startingnumber = 9 Then
Cells(startingnumber, 1).Interior.Color = RGB(0, 0, 0)
ElseIf startingnumber = 2 Or 4 Or 6 Or 8 Or 10 Then
Cells(startingnumber, 1).Interior.Color = RGB(255, 0, 0)
End If
Next startingnumber
End Sub
But if I were to change my code to this it will not:
Code:
For startingnumber = 1 To endingnumber
If startingnumber = 1 Or 3 Or 5 Or 7 Or 9 Then
Cells(startingnumber, 1).Interior.Color = RGB(0, 0, 0)
ElseIf startingnumber = 2 Or 4 Or 6 Or 8 Or 10 Then
Cells(startingnumber, 1).Interior.Color = RGB(255, 0, 0)
End If
Next startingnumber
Thanks
JV