Using an On Error statement in your VBA code causes Excel to bypass its built-in error handling and use your own error-handling code. In the previous example, a run-time error causes macro execution to jump to the statement labeled BadEntry. As a result, you avoid Excel's unfriendly error messages and you can display your own (friendlier, I hope) message to the user.
Notice that the example uses an Exit Sub statement right before the BadEntry label. This statement is necessary because you don't want to execute the error-handling code if an error does not occur.
Was this article helpful?