Excel vba on error exit loop
#EXCEL VBA ON ERROR EXIT LOOP CODE#
so that it will skip that line of code and moves on to the third step of code and calculate the value. To rectify or handle this runtime error, I have to use or execute the OnError Resume Next statement above a second code or at the beginning of code below the substatement. So, here, if further click on Step Into option or F8 key, the third calculation in this code will not get executed. Now, if I even click on debug, it can’t proceed further, where it will take me to the second line of code (It gets highlighted in yellow color), where I need to do the correction. 9 can’t be divided by zero in the second step. When I run the second line of code, then below mentioned runtime error occurs at the second step of a code, where any number can’t be divided by zero, i.e. I just copy the above code and start running it step by step, for the first step of calculation message box 3 appears.
![excel vba on error exit loop excel vba on error exit loop](https://www.exceldemy.com/wp-content/uploads/2017/09/5.png)
![excel vba on error exit loop excel vba on error exit loop](https://i.stack.imgur.com/IowTh.png)
Now, I run the above code, by clicking on step Into option or F8 key frequently, step by step. Suppose if you run the macro without entering On Error Resume Next statement, now I can execute the code step by step with the help of step into or F8 key to understand how it works.
![excel vba on error exit loop excel vba on error exit loop](https://i.stack.imgur.com/Km9Us.png)
In the above-mentioned example, you can observe a second calculation where any number can’t be divided by zero, i.e. In the below-mentioned example, I have to make a 3 calculation i.e. I can use On Error Resume Next anywhere in the code from the beginning to the end. If On Error Resume Next in entered at the top of code after SUB statement, it ignores runtime error and moves on to next statement, results in an output of 6/2 (Popup message box with result of it).