I'm writing some vba functions. In particular, i'm rewriting the VLOOKUP... In this MY_VLOOKUP, I have two boolean variable : 1. error_range, it's true if the range passed in the formula arguments is invalid 2. not_ava, it's true if there is no result (the VLOOKUP result would be #N/A)
In the error handler section i wrote
Errorhandler:
If error_range Then error_cat = xlErrRef
If not_ava Then error_cat = xlErrNA
Err.Raise error_cat
but I get a "#VALUE" error in the cell. When debugging, i realised that err.raise doesn't work and generates this "#VALUE" error How can i get a "#N/D" o "#REF" error in the cell?
You can get many errors when using Excel Formulas. They can be like
#Ref
,#Value
,#N/A
,#Name
etc.I usually use
CVERR()
to trap these kind of errors. Here is an example.I paste the code , maybe it will bu useful for someone
(thanks to Siddharth Rout for the help)