[英]Error 2042 ("N/A") in Excel VLookup() Worksheet Function
Need some help to figure out strange VBA VLOOKUP
Type Missmatch
error.需要一些帮助来找出奇怪的 VBA
VLOOKUP
Type Missmatch
错误。 The code is really simple, since sss0 is a random number and all I want is to find closest value in a range (sheet 'BMD_CDF', Range("A2:B999")).代码真的很简单,因为 sss0 是一个随机数,我想要的只是在一个范围内找到最接近的值(表 'BMD_CDF', Range("A2:B999"))。 In the spreadsheet, I set format for Sheets("BMD_CDF").Range("A2:B999") to scientific already...
在电子表格中,我已经将 Sheets("BMD_CDF").Range("A2:B999") 的格式设置为科学...
Dim LookUp_Range As Range
Dim sss0 As Double
Set LookUp_Range = Sheets("BMD_CDF").Range("A2:B999")
sss0=Application.WorksheetFunction.Max(Rnd(), 0.005)
Debug.Print Application.VLookup(sss0, LookUp_Range, 2, 0)
The Error 2042
("N/A") seems to be caused by the fact that the value returned by the Excel Worksheet function: Error 2042
(“N/A”)似乎是由 Excel 工作表函数返回的值引起的:
Aplication.WorksheetFunction.Max(Rnd(), 0.005)
which is always less than 1 will never get into specified range of values (>6) in column A
.始终小于 1 的值永远不会进入
column A
指定的值范围 (>6)。 For testing purpose, try to substitute it with any number in that range of values in Column A
, for example, sss0 =6.15
and modify the VLOOKUP() statement as following:出于测试目的,尝试将其替换为
Column A
中该范围内的任何数字,例如, sss0 =6.15
并修改 VLOOKUP() 语句如下:
Debug.Print Application.VLookup(sss0, LookUp_Range, 2, 1)
(where 1 stands for logical TRUE
) to get it working, ie finding the closest value (not exact match) as per your definition. (其中 1 代表逻辑
TRUE
)以使其工作,即根据您的定义找到最接近的值(不完全匹配)。
Hope this may help.希望这可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.