How to Exit loop in Excel 2010 VBA

Excel can sometimes get stuck in a loop if you are using some of its more advanced features. This tutorial will show you how to exit loop in excel vba.



Step # 1 – Load the Sheet that Loops
First of all load the Excel sheet that has the macro in that is getting stuck in a loop. Here we have a program that runs a simulation of lottery numbers. When we click the “Auto Bet” button, the program will keep running until it gets 6 hits on the lottery numbers. This can take an exceptionally long time to complete.
Running the loop

Step # 2 – Aborting the Loop
Now that the loop is running we may want to end it early. To do this you need to use the keyboard. Hold down the “Control” key and at the same time press the “Pause Break” key. This will most probably end the cycle as it does here. A window will appear telling you that the process has been aborted. This is the normal way of how to exit loop in excel vba.
Loop successfully aborted

Step # 3 – Alternative Solution
Sometimes the “Control” and “Pause Break” solution will not work and Microsoft Excel will become unresponsive. If this is the case you can press the “Control”, “Alt” and “Delete” buttons all at the same time. A blue screen will appear, click “Start Task Manager”. “Windows Task Manager” will appear and you need to locate “Microsoft Excel” and then click “End Task” in the bottom right. This will close the program, and end the loop, but you will lose any unsaved changes.
Forcing the loop to end with Task Manager