【发布时间】:2012-07-18 08:03:41
【问题描述】:
我在 Excel 中有一个数据表,与:
A B
-------------
1. aaa 11
2. bbb 22
3. ccc #N/A
4. ddd 44
我写了一个 VBA 函数来按键获取值(col B)(在 col A 中)
例如:=getValue(A1)
在这个例子中,如果我输入=getValue(A3),函数是 throw #VALUE!错误。我正在调试并在 VLOOKUP 函数中看到错误。这是我的代码:
Public Function getValue(ByVal key As Variant)
'get value of the cell at column B which has value 'key' at column A on same row
column2GetValue = 2
useClosestMatch = False
'error here if colum2GetValue contain #N/A
found = Application.WorksheetFunction.VLookup( _
key, _
Worksheets(SHEET_CACHE_NAME).Range("A:B"), _
column2GetValue, _
useClosestMatch _
)
getValue = found
End Function
如何在 VBA 中 VLOOKUP 获取 #N/A 值? 感谢您的帮助!
【问题讨论】:
标签: excel error-handling vlookup vba