简体   繁体   中英

Vlookup with wildcard not working (partial string match) on long values

I understand the basic use of the vlookup with wildcard but I'm running into a problem lately.

I need to lookup a value that contained in a cell as a part of string. In the below Sample I look up colA in the colC, with should be found, then return the values in col D into col B .

I use =VLOOKUP("*"&A1&"*",C$1:D$2,2,0) , and it only works for B1 .

Why do B2 & B3 don't work out the same way? Any solution?

Sample:

样品

As per your investigation and comment by Axel, VLOOKUP doesn't work with values over 255 characters in length. A workaround is use an array formula with the SEARCH function which handles much longer values. Double click into cell B1 and paste this formula, then save it by pressing CTRL + SHIFT + ENTER instead of just pressing Enter by itself:

=INDEX($D$1:$D$2,MATCH(TRUE,ISNUMBER(SEARCH(A1&",",$C$1:$C$2&",")),0))

If you enter it correctly, selecting the cell will show {curly braces} around the formula and it should evaluate to your desired result.

This formula first creates an array searching for the position of A1 in every cell in C1:C2. The array will consist of numbers (when A1 is found) and errors (when A1 is not found).

ISNUMBER then creates an array of TRUE (when A1 is found) and FALSE (when A1 is not found)

MATCH then finds the first TRUE value in the array.

INDEX then returns the corresponding value from the D1:D2.

Edit: The formula now searched for the value in A1 followed by a comma. This ensures that an exact match is made. To also ensure that the formula can match against the last value in any cell in column C, a comma is also added to the end of the values in column C.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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