简体   繁体   中英

Ignore spaces in data using VLOOKUP

    |                      A                 |      B               |     C 
----|----------------------------------------|----------------------|-----------
1   | All Countries     ="All Countries"     |    Search Citeria:   |   Germany       
2   |   Europe          ="   "&"Europe"      |    Result:           |   Germany
3   |     Germany       ="     "&"Germany"   |                      |
4   |     Spain         ="     "&"Spain"     |                      |
5   |     France        ="     "&"France"    |                      |
6   |   Asia            ="   "&"Asia"        |                      |
7   |     China         ="     "&"China"     |                      |
8   |     Japan         ="     "&"Japan"     |                      |
9   |                                        |                      |
10  |                                        |                      | 

In Column A in the table I have listed different countries using the formulas that I displayed on the right side.
As you can see these formulas contain spaces =" "& to make the list looking more structured.


Now, in Cell C1 I want to enter a country as a Search-Criteria for a VLOOKUP in Cell C2 .

=VLOOKUP($C1,$A$1:$A$8,1,FALSE)

As a result I get #NA which is probably caused by the spaces I use.

Do you have any idea how I can modify the VLOOKUP so it ignores the spaces?


NOTE: I know I could solve the issue by increasing the indentlevel instead of using the =" "& logic.
However, for other purposes I need to go with the =" "& instead of the indentlevel .

If your goal is simply to check if "Germany" exists, you could use wildcards:

=IF(COUNTIF(A2:A8,"* "&C1),C1,"Not found")

I still used a space in the criteria simply to avoid C1 being part of a larger string.

Btw, you can also implement wildcards in your VLOOKUP :

=VLOOKUP("* "&C1,A2:A8,1,FALSE)

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