'------ start of code -------
Sub ErrorDemo2()

    ' Establish in-line error-handling.
    ' The statement below tells VBA to not to transfer
    ' control anywhere else in the event of an error, but 
    ' instead to let the subsequent statements handle
    ' (or ignore) the errors.

    On Error Resume Next

    ' The bulk of the procedure code goes here.

    '** The following statement will raise an error. **
    Debug.Print 1 / 0     ' <--- ERROR: can't divide by zero.
    ' Check for any error raised by the preceding statement(s).
    Select Case Err.Number

        Case 0
            ' Do nothing; no error has occurred.

        Case 11
            MsgBox "You tried to divide by zero, you dummy!"
            ' Note:  here, we choose to let execution continue.

        Case Else
            MsgBox _
                "An unexpected error has occurred.  The system's description " & _
                    "of this error is:" & vbCr & vbCr & _
                    "Error " & Err.Number & ": " & Err.Description, _
                vbExclamation, _
                "Unexpected Error"

            ' Possibly we won't want to continue after this error.
            Exit Sub

    End Select

    ' If we want to execute more statements and check whether
    ' they raise errors, we need to clear this error.        
    Err.Clear

    ' ... more code here ...

End Sub
'------ end of code -------