Skip to next iteration in loop vba Skip to next iteration in loop vba vba vba

Skip to next iteration in loop vba


For i = 2 To 24  Level = Cells(i, 4)  Return = Cells(i, 5)  If Return = 0 And Level = 0 Then GoTo NextIteration  'Go to the next iteration  Else  End If  ' This is how you make a line label in VBA - Do not use keyword or  ' integer and end it in colon  NextIteration:Next


Just do nothing once the criteria is met, otherwise do the processing you require and the For loop will go to the next item.

For i = 2 To 24    Level = Cells(i, 4)    Return = Cells(i, 5)    If Return = 0 And Level = 0 Then        'Do nothing    Else        'Do something    End IfNext i

Or change the clause so it only processes if the conditions are met:

For i = 2 To 24    Level = Cells(i, 4)    Return = Cells(i, 5)    If Return <> 0 Or Level <> 0 Then        'Do something    End IfNext i


I use Goto

  For x= 1 to 20       If something then goto continue       skip this code  Continue:  Next x