To create a new function that you can call from a worksheet, just change the word Sub to Function. You can also add arguments, the same as regular worksheet functions.
Use the statement Application.DisplayAlerts = False to tell Excel not to display a warning message-for example, when deleting a worksheet.
To simply ignore a possible error in one or two statements-for example, when deleting a file or worksheet-put the statements into a subroutine and add the statement On Error Resume Next at the top of the subroutine.
Use the Err object-particularly the Number and Description properties-to find out information about an error that occurred in a macro statement.
Use On Error GoTo along with the name of a label to force any errors to jump to a single error handler that begins with the specified label.