在VBA函数中管理典型的Excel公式错误 [英] Managing typical excel formula errors in vba functions
问题描述
我正在编写一些vba函数。
特别是我正在重写VLOOKUP ...
在此MY_VLOOKUP中,我有两个布尔变量:
1. error_range,如果在公式参数中传递的范围无效,则为true
2. not_ava,如果没有结果,则为true(VLOOKUP结果为#N / A)
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
,但单元格中出现 #VALUE错误。
调试时,我意识到err.raise不起作用并生成此 #VALUE错误
如何在单元格中获取#N / D或 #REF错误?
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?
推荐答案
我粘贴代码,也许对某人有用
I paste the code , maybe it will bu useful for someone
(感谢Siddharth Rout的帮助)
(thanks to Siddharth Rout for the help)
If error_range Then
error_cat = xlErrRef
Else
If not_ava Then
error_cat = xlErrNA
else
error_cat = xlErrValue
End If
end if
my_vlookup = CVErr(error_cat )
这篇关于在VBA函数中管理典型的Excel公式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!