Stop infinite loop to coninue new loop

Nicobisgaard60

New Member
Joined
Sep 4, 2016
Messages
14
Hello,

I have a loop that runs for a long time, and when it meets a criteria i need it to stop the loop and continue on to the next part of the code.

Code:
Sub InfiniteLoop()

    
    For x = 1 To 4
    Sheets(x).Select
    For i = 1 To 9999999
    If XXX = False Then
         End
    End If
    Next i
    Next x
    
End Sub
The code starts with sheet 1, runs the macro and when the if-criteria is met, the formula stops and does not continue to the next sheets.
How do i rewrite the code so if the criteria is met, the code stops, only with that specific task and continues on to the next piece of code?

Just for clarification: I Posted this in another thread that was closed, so i apologize for that. I only use this code for peronal purposes, on workbooks that i created myself.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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