Skip to Loop

cmeier7

Board Regular
Joined
Jul 23, 2009
Messages
64
In a Do Loop, if I want to skip to the end of the loop somewhere inside the Loop (i.e. skip everything else in the loop and go back to loop over again, how do I do this?

I do not want to exit the loop, I mearly have a condition at the beginning of a loop that checks for shading and I want to repeat the loop if it is a specific color.

Thanks,
-cmeier7
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Well.. GoTo maybe an option.
but usually you want everything to be within If but sometimes that's not an option so..

Code:
Do While (condition)
    If (condition2) Then
        (code)
        GoTo continue
    Else
        (code)
    End If
continue:
Loop
 
Upvote 0
Personally I'd go with the If..Then..Else..Endif structure rather than the GoTo. I believe the use of GoTo can lead to poor program design and produces 'spaghetti' code which is less readable and more difficult to follow. As long as you indent your blocks correctly, adding one extra level of nesting is clearer than jumping around the code.

I've seldom been in a situation where the use of GoTo was unavoidable with the exception of On Error GoTo 0.
 
Upvote 0
I agree with Ruddles on using If..Then..Else..EndIf structure as I've previously stated.
But I do not agree that we are seldom put in a situation where GoTo is unavoidable.

In comparing and more complex algorithms (looping mostly), because of lack of VBA in looping functionalities (C Continue function) there was alot of time I had to use GoTo.

I think the reason why VBA developers have left out the functionality is because they didn't expect complex programming algorithms in VBA??
 
Upvote 0
Could you post the code you have so far?

The way I'd deal with this is write the code so that the loop performs all the hard work without having to stick goto's etc. For instance, it's possible to test the condtion for looping at the end

Code:
do
  'code here
loop while condition is true
for instance.
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,515
Members
452,921
Latest member
BBQKING

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