The code quoted by the OQ was by me. When I wrote it I actually considered the current question, too, but did not find a way to have the function return an ‘Err:nnn’ error in the way standard functions do. The .FormulaResultType
of a cell can only be 1 (number) or 2 (text). In case of standard functions/expressions returning an error the cells getting passed the final result show some relevant properties as follows:
.Type = 3 (meaning "formula")
.FormulaResultType = 1 (meaning "number")
.Value = 0
.Error = (code number of type Long)
.String = (the error message associated with the error's code number)
.Error
is read-only and if .String
gets an assignment, the property is set by a method afflicting everything else.
Thus: How? The problem is very similar to the one occurring with “additional number format routines” as I once tried. Even if I care for the function to know the cell from which it was called (This is not standard!) and try to “establish” a standard error by a side effect, this will be rejected (read-only .Error
) or destroy the functionality of the formula (set .String
).
I also could not find any service for the porpose. It seems to be outside of uno.
You may, of course, return an “impossible value” like -1
, and display an error message like “Err:502” based on a specific ‘Numbers’ format, but this is just a fake and will not care for the wanted propagation of the error. Returning a text of specific syntax was what I judged to come next to a solution.
(Edit:) To allow for a workaround concerning your problem, please first replace the dots in all the error messages of the quoted code with colons. Since even a silly sheetname can not commence with a colon, you may then delegate the task of producing the applicable error 502 to a standard function using a slightly tricky formula for a workaround:
=SHEETNAME(MySubExpression)&IF(LEFT(CURRENT();1)=":";SQRT(-1);"")
The uinmimicked error 502, if raised by SQRT, will propagate as expected.
Please tell me if you find a way! My former questions concerning this problem in different forums did not come up with a result.
(Edit2 - after a long time:)
Regarding the recent comment by @hhaddow I try to explain the above described workaround by this attached demo.