VBA Error Types

Compile Errors:  Errors that are recognized by the VBA compiler which stops the macro before it begins running.  Compile error must be resolved before the macro can run.

Runtime Errors:  Error that occurs when macro is running.  Runtime errors stop the macro mid sequence and will allow you to click debug to check what line is causing the error.  Error handlers can be used to prevent the macro from stopping and debugging.

Logical Errors:  Nothing coded incorrectly so there are NO hardblocks that would prevent the macro from running.  However the logic of the macro may be incorrect causing an incorrect result.


VBA Error Handlers

On Error Resume Next – Will continue running macro regardless of errors.

On Error GoTo 0 – Resets Error handling to default setting.  Will debug on runtime errors.

On error GoTo ErrorHandlerName –  Will run the code thats under the ErrorHandlerName: when a runtime error occurs.

On Error GoTo ErrorHandlerName
Exit Sub

ErrorHandlerName:
 'Error handling code goes  here, on error macro will go to this section and run this error handling code.
End Sub
vba error handlers

Interested in learning new skills?