简体   繁体   English

进行区分大小写的vlookup

[英]Doing a case sensitive vlookup

有谁知道如何使用Excel进行区分大小写的vlookup?

The key issue to a complete solution here is as Dick Kusleika observes: avoiding stopping the search when a case-insensitive match is found before the case sensitive one. 正如Dick Kusleika观察到的那样,此处完整解决方案的关键问题是:避免在区分大小写的匹配项之前找到不区分大小写的匹配项,避免停止搜索。

The Blog entry Case Sensitive Lookup in Excel claims to have a solution to this problem using the INDEX and MATCH functions (original info courtesy a post by Peo Sjoblom). Excel中的博客条目“区分大小写查找”声称使用INDEX和MATCH函数可以解决此问题(原始信息由Peo Sjoblom提供)。 There are some alternatives in the comments too. 评论中也有其他选择。

The newer AGGREGATE¹ function can pick up the first, second, third, etc. matches by forcing the non-matches into an error state and ignoring the errors. 较新的AGGREGATE¹函数可以通过强制不匹配进入错误状态并忽略错误来获取第一,第二,第三等匹配项。 Modify this method using the EXACT function to choose a case-sensitive lookup. 使用EXACT函数修改此方法以选择区分大小写的查找。

nam     date            code
bob     19-Oct-2015     001
BOB     02-Nov-2015     002
boB     28-Oct-2015     002
Bob     24-Oct-2015     004
bOB     27-Oct-2015     005
bOb     21-Oct-2015     006

Pick Bob and BOB from the mix with, 从中选择BobBOB

=INDEX(B$2:B$7, AGGREGATE(15, 6, ROW($1:$6)/EXACT($A$2:$A$7, $E2), 1))

Fill down and right as necessary. 根据需要填写并正确填充。

区分大小写的VLOOKUP


¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions. ¹AGGREGATE函数是Excel 2010引入的。在早期版本中不可用。

it seems to be a feature of vlookup that case does not matter - so Bob is the same as bob. 大小写似乎无关紧要是vlookup的一个功能-因此Bob与bob相同。 You could use code() to convert to ASCII and lookup on code. 您可以使用code()转换为ASCII并在代码上查找。 This would make your lookup more complicated, and code() only returns the code for the first item in the string. 这会使您的查找更加复杂,并且code()仅返回字符串中第一项的代码。

If the value you are returning is a number and not text, and if the first column of your lookup_table is unique ('bob' doesn't appear more than once), then you can use an array formula like this 如果返回的值是数字而不是文本,并且lookup_table的第一列是唯一的(“ bob”出现不止一次),则可以使用如下数组公式

=SUM(EXACT(A3:A6,"bob")*(B3:B6))

Enter with Control+Shift+Enter, not just enter. 输入Control + Shift + Enter,而不仅仅是输入。 It sums everything in B3:B6 where A3:A6 is exactly "bob". 它对B3:B6中的所有内容求和,其中A3:A6恰好是“ bob”。 Since there's only one "bob", it's only summing one cell. 由于只有一个“鲍勃”,所以只求和一个单元格。 Because it uses SUM, returning strings won't work. 因为它使用SUM,所以返回字符串将不起作用。

If 'bob' appears more than once, it will sum all the values, which you probably don't want. 如果“ bob”出现不止一次,它将对所有值进行求和,而这可能是您不希望的。

Update 更新资料

If the value you are looking up is not a number, you could use an array formula to find the row, then wrap an INDEX function around it. 如果要查找的值不是数字,则可以使用数组公式查找该行,然后在其周围包装一个INDEX函数。 Assume your data is A3:B6 and you want to pull data out of column B based on an exact match in column A. 假设您的数据是A3:B6,并且您想基于A列中的完全匹配项将数据从B列中拉出。

=INDEX(A3:B6,SUM(EXACT(A3:A6,"bob")*(ROW(B3:B6)))-2,2)

Enter with CSE. 使用CSE输入。 The SUM portion returns the row where "bob" is found. SUM部分返回找到“ bob”的行。 You have to subtract 2 from it because the data starts in A3 (subtract one less than the row where the data starts). 您必须从中减去2,因为数据从A3开始(比数据开始的行少1)。 The INDEX function uses that row and pulls from column B. INDEX函数使用该行并从B列中提取。

My first thought is to use the EXACT() function to test the result of the vlookup: 我的第一个想法是使用EXACT()函数测试vlookup的结果:

=IF(EXACT(VLOOKUP(A2,$C$2:$C$4,1,FALSE),A2),VLOOKUP(A2,$C$2:$C$4,1,FALSE),0)

Where A2 = the value you wish to look up and C2:C4 is the range containing the values to look up. 其中A2 =您要查找的值,C2:C4是包含要查找的值的范围。

This would return the result of the vlookup and confirm that it matched the case of the value you wish to look up. 这将返回vlookup的结果,并确认它与您要查找的值的大小写匹配。 It would return the vlookup result if they match case, or 0 otherwise. 如果大小写匹配,它将返回vlookup结果,否则返回0。

EDITED 已编辑

Actually this answer wouldn't work. 其实这个答案是行不通的。 If your list contained "Bob" and "bob" it would find the first one and only test that. 如果您的列表包含“鲍勃”和“鲍勃”,它将找到第一个并且仅对其进行测试。 Sorry, I didn't think of that. 抱歉,我没想到。

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

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