how to break out of an if statement and continue to loop

G

Guest

I'm really stuck. I grab a value from one page and go to another page to
find a match. All is well unless I can't find a match. I need to break out
of the inner loop and continue the outer. Here is my code. I can't figure
out how to break out yet continue execution. Thanks
(outer loop is here)
Do Until StrComp(destin_unit, source_unit) <> 0
If cntr2 < text_max_rows Then
cntr2 = cntr2 + 1
destin_unit = Cells(cntr2, 1)
Else
cntr2 = cntr3 + 1
'I need to break here and continue the outer loop
End If
Loop
 
M

merjet

Replace: 'I need to break here and continue the outer loop
With: Exit Do

Hth,
Merjet
 
G

Guest

Do you want something like this?

Sub demo()
For i = 1 To 100
greatescape = False
Do Until (StrComp(destin_unit, source_unit) <> 0) Or greatescape = True
If cntr2 < text_max_rows Then
cntr2 = cntr2 + 1
destin_unit = Cells(cntr2, 1)
Else
cntr2 = cntr3 + 1
greatescape = True
End If
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top