Okay, guys, so now we're going to introduce a very important statement that you're going to use a lot when handling errors, which is the on error statement. Okay, so let's say I've written this line of code here, worksheets, my worksheet does select, and actually, there isn't a worksheet that is called my worksheet in this workbook. So if you run that, you will get a runtime error. So straight out of range. So I'll press enter here and try to deal with my error. The simplest form of dealing with that error is to write on error resume next, saw an error resume.
Next, what it does is that it just simply ignores the error. So this statement is going to cause an error. We'll just ignore it and execute anything after it. So maybe message box, we have ignored the error. And if we just execute that, let's do it step by step actually. So on our zoom next year, And so now any statement is going to cause an error that is going to come after on error resume next the error is just gonna be ignored Okay, and please note that it is going to be for any statement that would cause an error not just this statement here worksheets my worksheet does select any statement that will cause error from now on after executing the on error resume next line of code is going to be ignored.
So now worksheets my worksheet select this school is an error but it actually is going to be ignored and then we'll execute this message box and that's it. Okay, so here the the macro ends. And so if we write actually another statement that would cause an error, so my worksheets, another worksheet, I'm just going to call it another worksheet dot select. So this one as well should cause an error but because as part of our macro execute this statement here on error resume next, this is going to affect this statement or it's going to be ignored and this statement as well. error is going to be one word and then we're going to get our message box. Well, that's a very easy way to ignore errors, but you're just ignoring them.
You're not handling them. You're not creating a workaround or a solution for the error. Okay, but this is the simplest form. Sometimes you're going to use it is the simplest thing that you can do. There are more sophisticated or more complex stuff that you can do on handling errors.