Some extra notes for a few Posts
http://www.eileenslounge.com/viewtop...278892#p278892
https://www.myonlinetraininghub.com/...andling-in-vba
https://excelfox.com/forum/showthrea...GoRoT-N0Nula-1
https://excelfox.com/forum/showthrea...0559#post10559


_.....continued from last post

The following other error things also , in addition to their main function, clear the Err object registers –
_ On Error GoTo 0 ,
_ changing the error handler
_ Resume, ( Resume; Resume Next; Resume [label] )
,
Here are 5 demos
1x On Error GoTo 0
1x changing the error handler
3x Resume, ( 1xResume; 1xResume Next; 1xResume [label] )

Code:
Sub OnErrorGoTo0ClearsErr() ' _ On Error GoTo 0
Dim Rslt As Double
 On Error Resume Next ' In simple terms this allows the code to contiunue as if no error had occured. It is not quite that simple, for example, the  Err  and  Error   are filled
Debug.Print Err & vbCr & vbLf & Error '   gives 0    The default  Err  property is the error number, so in this situation  Err  is taken as  Err.number    The exact working of  Error  is unclear, but if an error occurs it seems to do a few things, and one of them is that it returns the error description
 Let Rslt = 1 / 0
Debug.Print Err & vbCr & vbLf & Error '   gives   11  Division durch Null
 On Error GoTo 0      '  The main purpose of this is to disable our error handler and return to the default VBA error handler.  As a secodary function it seems to clear the  Err  registers
Debug.Print Err & vbCr & vbLf & Error '   gives 0
End Sub

Sub ChangingTheErrorHandlerClearsErr() ' _ changing the error handler
Dim Rslt As Double
 On Error Resume Next ' In simple terms this allows the code to contiunue as if no error had occured. It is not quite that simple, for example, the  Err  and  Error   are filled
Debug.Print Err & vbCr & vbLf & Error '   gives 0    The default  Err  property is the error number, so in this situation  Err  is taken as  Err.number    The exact working of  Error  is unclear, but if an error occurs it seems to do a few things, and one of them is that it returns the error description
 Let Rslt = 1 / 0
Debug.Print Err & vbCr & vbLf & Error '   gives   11  Division durch Null
 On Error Resume Next
Debug.Print Err & vbCr & vbLf & Error '   gives 0    because I have changed the error handler , ( admitedly in this case changed it to the same type )
 Let Rslt = 1 / 0
Debug.Print Err & vbCr & vbLf & Error '   gives   11  Division durch Null
 On Error GoTo Bed
Debug.Print Err & vbCr & vbLf & Error '   gives 0    because I have changed the error handler
 Let Rslt = 1 / 0
Exit Sub ' I don't need this since i never come here, but its good practice to get in the habit of having this above a typical Error handling code section.
Bed:
Debug.Print Err & vbCr & vbLf & Error '   gives   11  Division durch Null
End Sub

Sub Resume_ClearsErr() ' _ Resume, ( Resume )
Dim Rslt As Double, Demonostrator As Long
 On Error GoTo ErrHndler ' In simple terms this tells VBA to go the the label,  ErrHndler   Note however that if an error causes me to go there, then I will then be in the exception state.
Debug.Print Err & vbCr & vbLf & Error    '   gives 0    The default  Err  property is the error number, so in this situation  Err  is taken as  Err.number    The exact working of  Error  is unclear, but if an error occurs it seems to do a few things, and one of them is that it returns the error description
 Let Rslt = 1 / Demonostrator  '  Initially this causes me to go to  ErrHndler   but then the  Resume  brings me back to re try this code line
Debug.Print Err & vbCr & vbLf & Error    '   gives 0    The  Resume  cleared the  Err  registers
Exit Sub

ErrHndler:  ' Start of a what is commonly called an "error handling code section"
Debug.Print Err & vbCr & vbLf & Error '   gives   11  Division durch Null   The  Err   register  is always filled in all situatiuons when an error occurs, regardless of what error handler is or isn't in place.
 Let Demonostrator = 1  ' It is important to cure the problem causing the error here, or otherwise the next code line will cause an infinite loop because the next code line instructs VBA to go back and try the erroring code line again.   Note also that the  Resume  in the next code line also clears the error exception and clears the  Err   registers
Resume ' This clears the exception,  clears the  Err  registers, and instructs VBA to go back to the code line that errored and try again.  Because it instructs VBA to go back and try the erroring code line again, It is important to cure the problem causing the error before this code line, or else we will have an infinite loop
End Sub
Sub Resume_Next_ClearsErr() ' 'Resume, (  Resume Next )
Dim Rslt As Double
 On Error GoTo ErrHndler ' In simple terms this tells VBA to go the the label,  ErrHndler   Note however that if an error causes me to go there, then I will then be in the exception state.
Debug.Print Err & vbCr & vbLf & Error    '   gives 0    The default  Err  property is the error number, so in this situation  Err  is taken as  Err.number    The exact working of  Error  is unclear, but if an error occurs it seems to do a few things, and one of them is that it returns the error description
 Let Rslt = 1 / 0  '  This causes me to go to  ErrHndler  The  Resume Next  brings me back to just after this code line
Debug.Print Err & vbCr & vbLf & Error    '   gives 0    The  Resume Next  cleared the  Err  registers
Exit Sub

ErrHndler:  ' Start of a what is commonly called an "error handling code section"
Debug.Print Err & vbCr & vbLf & Error '   gives   11  Division durch Null   The  Err   register  is always filled in all situatiuons when an error occurs, regardless of what error handler is or isn't in place.
Resume Next ' This clears the exception,  clears the  Err  registers, and instructs VBA to go back to the code line just after that code line that errored
End Sub
Sub Resume_LABEL_ClearsErr() ' 'Resume, (  Resume [label] )
Dim Rslt As Double
 On Error GoTo ErrHndler ' In simple terms this tells VBA to go the the label,  ErrHndler   Note however that if an error causes me to go there, then I will then be in the exception state.
Debug.Print Err & vbCr & vbLf & Error    '   gives 0    The default  Err  property is the error number, so in this situation  Err  is taken as  Err.number    The exact working of  Error  is unclear, but if an error occurs it seems to do a few things, and one of them is that it returns the error description
 Let Rslt = 1 / 0  '  This causes me to go to  ErrHndler  The  Resume Lbl  brings me back to just after the label,  Lbl:

Lbl:
Debug.Print Err & vbCr & vbLf & Error    '   gives 0    The  Resume Lbl  cleared the  Err  registers
Exit Sub

ErrHndler:  ' Start of what is commonly called an "error handling code section"
Debug.Print Err & vbCr & vbLf & Error '   gives   11  Division durch Null   The  Err   register  is always filled in all situatiuons when an error occurs, regardless of what error handler is or isn't in place.
Resume Lbl ' This clears the exception,  clears the  Err  registers, and instructs VBA to go to the  code line just after the label  Lbl:
End Sub
If we use On Error GoTo [LABEL] and then use Resume ( Resume; Resume Next; Resume [label] ) then we appear to be having something done very similar, or possibly exactly the same as On Error GoTo -1 , since the exception state is cleared and the Err object is cleared.
To demonstrate this we can do the last three routines again, and simply add another error handler , for example On Error Resume Next , after the return point, and follow this by an error. If the error is handled, that is to say we get no default VBA error message, then we know that the exception had been cleared previously. If it had not been cleared then the new error handler, On Error Resume Next , would have been ignored and we would have seen the default VBA error handler warning pop up message.

_..... continued in next post