User FAQs

If you have a question, please send it to us.

1) What is the easiest way to avoid errors ?
Try and write very small procedures and functions.
Every subroutine or function should only do one thing.

2) What does On Error Resume Next mean ?

On Error Resume Next 

Adding this line above your code will mean that if an error is encountered it will be ignored and execution will continue to the next line.
The scope of this statement is to the end of the subroutine or function (Exit Sub, End Sub, Exit Function, End Function).
If another On Error statement is reached any subsequent errors will be handled differently.
Assuming your (Tools > Options)(General Tab, "Break on All Errors") is not selected.

On Error Resume Next 

Dim lNumber As Long
Dim sText As String
lNumber = "100 / 0"
Debug.Print "ignores the first error"
sText = 100 / 0
Debug.Print "also ignores the second error"

3) What does On Error GoTo 0 mean ?

On Error GoTo 0 

Resets the Err object and resets the Err.Number to zero.
Disables any enabled error handling in the current subroutine or function.
If you want any error handling after this statement it must be re-enabled.

4) What does On Error GoTo -1 mean ?
Clears the error handling (Err object) allowing you to define another error trap.

On Error GoTo -1 

5) Can you describe the Error Function ?
This function returns the error message that corresponds to a given error number.
The line below displays the text "Type mismatch".

Debug.Print VBA.Error(13) 

6) Can you describe the Error Statement ?
This statement can be used to simulate the occurrence of an error and is only available for backwards compatibility.
Err.Raise replaces this statement and should be used instead.

Error 13         'type mismatch error  
Error 9999 'application-defined or object-defined error

Call Error(13) 'does not work and will generate an error


7) Is it possible to create your own user defined errors ?
Yes. You can create error values using the CVERR function.

Dim MyError As Variant 
MyError = VBA.CVErr(13)
Debug.Print VBA.TypeName(myError) 'Error
Debug.Print VBA.VarType(myError) '10

You can use the ISERROR function to test for this value.

Debug.Print VBA.IsError(MyError)    'True  

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext