简体   繁体   中英

Excel 2013 - VLOOKUP with Multiple Criteria

I am using VLOOKUP in a column for every row in a spreadsheet. For each row I need to return a value from another sheet if two criteria are met: 1) The value in column A of the same row = the value from the range referenced 2) The value in column O in the range = "AH"

So the following works to return the value of my first criteria above, but I don't want the value returned unless the value in O:O of the matching row is "AH". I've searched several sites and tutorials, but nothing seems to reference what I am trying to do. They either want to count or sum values and I don't want to do any fancy calculations. I just want to return the values if they are "AH" for the matching record in the other table.

=VLOOKUP($A2, Cohort_Major_IDST!$A:$AF, 15, FALSE)

Many thanks in advance,

Lindsay

This is a tricky one and there are several ways to solve it.

The first method is to make a "Key" in the sheet to which you are looking up where you concatenate the value in A with the value in O into a new column at the front of the range (Column A inserted) and then lookup like =Vlookup($A2 & "AH", Cohort_Major_IDST!$A:$AG, 6, FALSE)

The second is to get sneaky with SUMPRODUCT to return the row where the two conditions are found, and INDEX to get the value:

=INDEX(Cohort_Major_IDST!$AH, 0, SUMPRODUCT(($A2=Cohort_Major_IDST!A:A)*(Cohort_Major_IDST!O:O="AH")*ROW(Cohort_Major_IDST!A:A)))

The SUMPRODUCT here looks at multiple criteria in similar ranges (here the similar ranges are columns A and O). If the criterian match for a row, then it takes the value from ROW(Cohort_Major_IDST!A:A).

This second method is nicer since it doesn't involve inserting superfluous columns into your range so you can leave your raw data untouched. It's not so friendly looking though, and it also fails if there are more than one match in the multiple criterias in the data. It will add the results of all the ROW()'s returned... so make sure your look up is unique.

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