简体   繁体   中英

How can I conditionally VLOOKUP in Excel?

Suppose I have the table I need to VLOOKUP() through:

id |  indicator | value
-----------------------
1  |  a         | abc
1  |  b         | def
1  |  c         | ghi
2  |  a         | bbc
2  |  b         | bef
3  |  a         | aef

There is a table where I need to attach only values with indicator equal to a :

id | value
----------
1  | abc
2  | bbc
3  | aef

Something like conditional VLOOKUP() is required. What is the elegant way to do it?

Use an array formula:

I found this formula in the web a few years ago, cant remember where, but credit to them.

=VLOOKUP(CONCATENATE(D2,"a"), CHOOSE({1,2},A$1:A$10 & B$1:B$10, C$1:C$10 ),2,0)

For this example I used column D on the same sheet for the reference ID and column E for the result. Amend the references as required.

Due to this being an array formula, every time the formula is entered you will need to select the formula bar and hold CTRL and Shift and press enter on the keyboard.

You can do multiple criteria INDEX-MATCH to achieve this:

=INDEX($C$1:$C$6,MATCH($E1&"a",$A$1:$A$6&$B$1:$B$6,0))

This is array formula and it works by hitting Ctrl + Shift + Enter .

Also, I assumed that your Lookup value is in cell E1, which is something you can change according to your needs.

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