This is a terrific book by Rob.
My two cents of error handling (either for a procedure or for a function) are based on KISS (keep it just stupid)
Understand what you want from an error handler?
This is usually what I want / expect from my error handler ...
- The line in which the error occurred.
- Error number
- Error message
- Reset Events, if applicable
Allows you to break the above. Since you already know what your error handler looks like, consider this example.
Sub Sample() Dim i As Integer, j As Integer On Error GoTo Whoa Application.ScreenUpdating = False i = 1111111111 For j = 1 To i Debug.Print ThisWorkbook.Sheets(1).Cells(i, 1).Value Next i LetsContinue: Exit Sub Whoa: MsgBox Err.Description Resume LetsContinue End Sub
This is a very simple error handler, but it helps me a lot. So let's now tweak it to make it more useful. If you run the code above, you will receive an error message, as shown in the screenshot below, and if you notice, this will not help.

Now consider all the points that I mentioned in Logic above
- The line in which the error occurred.
There is a property called ERL , which few people know about. You can use it to get the line number of the code where the error occurred. To do this, you need to specify your code number. See this example.
Sub Sample() Dim i As Integer, j As Integer 10 On Error GoTo Whoa 20 Application.ScreenUpdating = False 30 i = 1111111111 40 For j = 1 To i 50 Debug.Print ThisWorkbook.Sheets(1).Cells(i, 1).Value 60 Next j LetsContinue: 70 Exit Sub Whoa: 80 MsgBox Erl 90 Resume LetsContinue End Sub
When you run the above code, you will get this

So now I know that the error occurred on line 30, which i = 1111111111
Go to the next
- Error number
- Error message
The error number and error message can be obtained from Err.Number and Err.Description respectively. So now combine the ERL , Err.Number and Err.Description
Check out this example.
Sub Sample() Dim i As Integer, j As Integer 10 On Error GoTo Whoa 20 Application.ScreenUpdating = False 30 i = 1111111111 40 For j = 1 To i 50 Debug.Print ThisWorkbook.Sheets(1).Cells(i, 1).Value 60 Next j LetsContinue: 70 Exit Sub Whoa: 80 MsgBox "The Error Happened on Line : " & Erl & vbNewLine & _ "Error Message : " & Err.Description & vbNewLine & _ "Error Number : " & Err.Number 90 Resume LetsContinue End Sub
When you run this code, you will get something like this.

You can further customize the error message to make it more user friendly. for instance
'~~> Message you want to deliver to the user in case the error happens Const sMsg As String = "Please take a screenshot of this message and contact the developer for a resolution" '~~> Title of your message box Const sTitle As String = "Oopsie Daisies" '~~> Change the above as applicable Sub Sample() Dim i As Integer, j As Integer 10 On Error GoTo Whoa 20 Application.ScreenUpdating = False 30 i = 1111111111 40 For j = 1 To i 50 Debug.Print ThisWorkbook.Sheets(1).Cells(i, 1).Value 60 Next j LetsContinue: 70 Exit Sub Whoa: 80 MsgBox "The Error Happened on Line : " & Erl & vbNewLine & _ "Error Message : " & Err.Description & vbNewLine & _ "Error Number : " & Err.Number & vbNewLine & vbNewLine & _ sMsg, vbCritical, sTitle 90 Resume LetsContinue End Sub

To the next:)
Reset Events, if applicable
When you work with events and an error occurs, if error handling is missing, the code is interrupted. Unfortunately, this does not reset events. It is very important that you reset events in the error handler.
If you notice in the above code, we set Application.ScreenUpdating = False . When the code breaks, this event does not receive a reset. In this case, you will have to handle this in the LetsContinue error LetsContinue . See this example.
'~~> Message you want to deliver to the user in case the error happens Const sMsg As String = "Please take a screenshot of this message and contact the developer for a resolution" '~~> Title of your message box Const sTitle As String = "Oopsie Daisies" '~~> Change the above as applicable Sub Sample() Dim i As Integer, j As Integer 10 On Error GoTo Whoa 20 Application.ScreenUpdating = False 30 i = 1111111111 40 For j = 1 To i 50 Debug.Print ThisWorkbook.Sheets(1).Cells(i, 1).Value 60 Next j LetsContinue: 70 Application.ScreenUpdating = True 80 Exit Sub Whoa: 90 MsgBox "The Error Happened on Line : " & Erl & vbNewLine & _ "Error Message : " & Err.Description & vbNewLine & _ "Error Number : " & Err.Number & vbNewLine & vbNewLine & _ sMsg, vbCritical, sTitle 100 Resume LetsContinue End Sub
Like Philip, I also highly recommend using MZ-Tools for VBA. I use it now for donkeys ...
Hope this helps.