VBA returns “n / a” and other error information

When we use Excel’s built-in functions to return A Value, if the argument is wrong or cannot be found, we often return #N/A or #Value! And so on prompt message.
Can the VBA code we write in the module also return this information?
The answer is yes, because the code in the module itself can be called within the formula, so naturally this information can also be returned.
However, it is important to note that this information is not text, it is a built-in error value!
The following table shows some commonly used error values for reference:


Error Number

Cell Error value



0 # DIV /!
xlErrNA 2042 #N/A
xlErrName 2029 #NAME?
xlErrNull 2000 #NULL!
xlErrNum 2036 #NUM!
xlErrRef 2023 #REF!
xlErrValue 2015 #VALUE!

returns the value by calling CVErr(error constant), so what you see on the interface is the error value we want to display.
Such as:

Read More: