Using a VLOOKUP lookup_value that contains a formula

六眼飞鱼酱① 提交于 2019-12-13 17:26:14

问题


Using Excel I am using a VLOOKUP where the lookup_value contains a formula that generates the string that should be searched. The formula:

=VLOOKUP(MID(A2,2,5),Sheet2!A:B,2,0)

All results come back with #N/A, yet if i substitute the MID() function with the value it generates the VLOOKUP functions fine.

Example data:

Sheet1

$#00001#
$#00002#

Sheet 2

00001 | Hello
00002 | World

回答1:


The 00001 in sheet2 is actually a 1 in a cell that has been formatted as "00000" to display leading zeroes. This does not alter the raw underlying value of 1. You will need to convert the MID result to a true number with a double unary like,

 =VLOOKUP(--MID(A2,2,5),Sheet2!A:B,2,0)

You cannot lookup text-that-looks-like-a-number in a column of true numbers regardless of how the true numbers are formatted for display.

Tip: Unless you manually change the cell alignment, text is left-aligned by default; numbers are right-aligned by default. This is a quick visual check that can prove the above scenario.




回答2:


i agree with Jeeped's answer. however, looks like if $ was a literal, formula should actually contain

MID(A2,3,5)

as 00001 starts at position 3.

Formatting the column A in Sheet2 as Text is also a solution.

P.S. i am writing as answer since i was unable to comment on the question instead.



来源:https://stackoverflow.com/questions/42966850/using-a-vlookup-lookup-value-that-contains-a-formula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!