J
Junior728
hi,
i am trying to use a If-Else Loop or If-ElseIf-Else loop,but the VB editor
keep prompting me a mistake with Use "Next..without For" comment. Is it
something wrong with my if-else function or otherwise. Pls advise.
My Example:
Sub COMPAREWH()
Dim LastRow
Range("A65536").Select
Selection.End(xlUp).Select
LastRow = ActiveCell.Row
LR$ = LastRow
Range("A2").Select
Sheets("Tabelle1").Select
'Start of For...Next Loop
For i = ActiveCell.Row To LastRow
COMPARE$ = Cells(i, 1).Value
Vlook$ = Cells(i, 4).Value
If COMPARE$ = "1" Then GoTo Skiptohere
ElseIf COMPARE$ = "2" Then
Cells(i, ActiveCell.Column).Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else: GotoSkiptohere
End If
Next i
Skiptohere:
ActiveCell.Offset(1, 0).Range("A1").Select
End Sub
i am trying to use a If-Else Loop or If-ElseIf-Else loop,but the VB editor
keep prompting me a mistake with Use "Next..without For" comment. Is it
something wrong with my if-else function or otherwise. Pls advise.
My Example:
Sub COMPAREWH()
Dim LastRow
Range("A65536").Select
Selection.End(xlUp).Select
LastRow = ActiveCell.Row
LR$ = LastRow
Range("A2").Select
Sheets("Tabelle1").Select
'Start of For...Next Loop
For i = ActiveCell.Row To LastRow
COMPARE$ = Cells(i, 1).Value
Vlook$ = Cells(i, 4).Value
If COMPARE$ = "1" Then GoTo Skiptohere
ElseIf COMPARE$ = "2" Then
Cells(i, ActiveCell.Column).Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else: GotoSkiptohere
End If
Next i
Skiptohere:
ActiveCell.Offset(1, 0).Range("A1").Select
End Sub