Restart a Loop from within an If statement?

jtsains

Board Regular
Joined
Apr 29, 2011
Messages
103
How to Restart Loop from begining when If statement is true? I am running a macro using a list of values in column A and using For and Next i to restart and loop through my data until the end of the list of data is reached.During the loop, I have If statements researching each value and if it equals a certain value then i need it to complete that loop and start the Next i over again.If A2 = 1 then process one way and restart loop with next data point (A3)If A2 = 2 then process a different way and restart loop with next data point (A3)If A2 = anything else, process a different ay and restart loop with next data point (A3)
Code:
________________________________________Dim i As Integer  For i = 2 To Range("A" & Rows.Count).End(xlUp).Row     Range("A" & i).Select      If Selection.Value = 1 then msgbox "HI"      ' ***I need something that when value = 1 it finds the next data point (Next i) and doesn't finish checking the rest of the below If Statements      End If      Selection.copy Range("B1").Select       ActiveCell.End(xlDown).Select       ActiveCell.Offset(1, 0).Select       Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False      If Selection.Value = 2 then Msgbox "Hello"      ' ***I need something that when value = 1 it finds the next i here and not finishing the rest of the if statements for this selection value.      Else        Selection.copy         Range("C1").Select         ActiveCell.End(xlDown).Select         ActiveCell.Offset(1, 0).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False      If Selection.Value = 2 then End If  Next iEnd Sub ________________________________________
Please do not focus on the actions that each statement is making, but only on how i can restart at the top with the Next i when the IF statement is true. :)Thank you in advance.Jeff
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
in essence you need to not have lots of if statements for the same thing rather more result statements

if ................................then...............................
elseif
..................................then...............................
else.............................
next i

end if
 
Upvote 0
MOre like this:
Code:
if ................................then...............................Next IIF..................................then...............................next iElseMsgbox "HELP ME"end if NExt i
 
Upvote 0
any idea why my code is being put all on one line instead of with vertically like the way i type it?
 
Upvote 0
i am useing "
Code:
" before my txt and "
" after my test. It is putting it into a window, just all on one line. (or at least that is how it is showing on my end. Does it look weird on your end too?
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,548
Members
449,170
Latest member
Gkiller

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top