VBA On Error Statement
The VBA on error statements is used for error handling. This statement performs some action when an error occurs during run time. Without an Error statement, any run-time error that occurs is misfortunate. Execution stops abruptly with an error message.
Most VBA error handling is done with the On Error Statement. The On Error statement instructs the VBA what to do if it encounters the error.
Below are On Error Statement:
- On Error GoTo 0
- On Error Resume Next
- On Error GoTo Line
VBA Error Handling
In a VBA code, there may be some errors like syntax errors, compilation errors, or runtime errors so we need to handle these errors. Suppose there is a code of 200 lines and the code has an error it’s very difficult to find an error in the code of 200 lines so it’s better to handle the error where we are expecting some error in our code. There are many error handling methods in VBA which we will discuss in this article but before that, we will discuss types of error.