简体   繁体   English

Excel VLOOKUP 在允许近似匹配时返回#N/A,但在要求完全匹配时返回值?

[英]Excel VLOOKUP returns #N/A when allowing approximate match, but returns value when requiring exact match?

Run across a very strange issue that I am curious about.遇到一个我很好奇的非常奇怪的问题。 In Excel, I was doing a VLOOKUP to match contact names with a unique ID found in another database.在 Excel 中,我正在执行 VLOOKUP 以将联系人姓名与在另一个数据库中找到的唯一 ID 进行匹配。 Formula for example: =VLOOKUP(B2,Sheet2:A,B,2,TRUE).例如公式:=VLOOKUP(B2,Sheet2:A,B,2,TRUE)。 very basic.非常基本。 I used approx, match but, of course.我用了近似,匹配但是,当然。 some instances still returned #N/A, However.但是,某些实例仍然返回#N/A。 I did double checks with a quick control-F and found a number of instances returning NA when there was in fact a (exact) match.我用快速的 control-F 进行了仔细检查,发现许多实例返回 NA 而实际上存在(精确)匹配。 I was troubleshooting and trying a number of things but nothing was working, Many checks confirmed the cells were equal, there was nothing tricky like hidden characters.我正在排除故障并尝试了很多东西,但没有任何效果,许多检查确认单元格是相等的,没有什么像隐藏字符那样棘手。 very peculiar, Anyway.很奇特,反正。 on a whim I changed from approximate match to exact match and lo and behold it worked!一时兴起,我从近似匹配更改为精确匹配,你瞧,它奏效了! The VLOOKUP was returning the correct value. VLOOKUP 正在返回正确的值。

I'm trying to understand why this is.我试图理解为什么会这样。 Obviously if you were requiring an exact match but there was only an approx.显然,如果您需要完全匹配但只有大约。 match it would return NA.匹配它会返回 NA。 But it doesn't make sense the other way around.但是反过来就没有意义了。 An exact match should be returned when allowing even approx.当允许甚至大约时,应返回完全匹配。 matches.火柴。 So just trying to understand what is going on behind the scene in VLOOKUP/Excel to make this phenomenon occur.所以只是试图了解 VLOOKUP/Excel 中的幕后情况,以使这种现象发生。

Appreciate any insight!欣赏任何见解!

When working with approximate VLOOKUP, the key-column (always the 1st column of matrix-range) in the lookup-matrix should always be sorted in ascending order.使用近似 VLOOKUP 时,查找矩阵中的键列(始终是矩阵范围的第一列)应始终按升序排序。 The reasons for this is the following:原因如下:

Imagine a key column with the values [2,3,10,4] in the given order.想象一个键列,其值按给定顺序 [2,3,10,4]。 When the key '4' should be looked-up approximately, the function will start comparing the available keys in the column, beginning with '2'.当应该大致查找键“4”时,function 将开始比较列中的可用键,从“2”开始。 After '3' was passed, '10' follows, which is already greater than the searched '4'. '3'被传递后,'10'紧随其后,已经大于搜索到的'4'。 Consequently, the function stops searching and returns the target value of the previous key-row ('3') as an "approximation".因此,function 停止搜索并返回前一个键行('3')的目标值作为“近似值”。

Now, given another example [10,2,3,4].现在,给出另一个例子 [10,2,3,4]。 Here, approx.在这里,大约。 VLOOKUP will stop searching right after the first key comparison as '10' is greater than the searched '4'. VLOOKUP 将在第一个键比较后立即停止搜索,因为“10”大于搜索到的“4”。 Since no previous key-row is available, the returned value will be #N/A.由于没有先前的键行可用,返回的值将是#N/A。 However, an exact VLOOKUP would have found the matching key as it does not stop searching.但是,精确的 VLOOKUP 会找到匹配的键,因为它不会停止搜索。

Besides key order, it is recommended to have all the key-values in the same format.除了键顺序外,建议所有键值都采用相同的格式。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM