9

I need to be able to find the row number of the row where matching criteria from A1 is equal or greater than values in column C and lesser or equal than values in column D

I can use INDEX and MATCH combo but not sure if this is something I should use for multiple criteria matching.

Any help or suggestions are highly appreciated.

3
  • 1
    What should happen if multiple valid combinations are found?
    – chancea
    Feb 12, 2015 at 21:32
  • Basically, I will use the row number to obtain value from Column E
    – AlexB
    Feb 12, 2015 at 21:33
  • So it should just return the first valid row?
    – chancea
    Feb 12, 2015 at 21:36

2 Answers 2

16

I would not use MATCH to get the row number since you have multiple criteria. I would still use INDEX however to get the value of the row in E once the proper row number was discovered.

So instead of MATCH I would use an array formula using an IF statement that contained multiple criteria. Now note that array formulas need to be entered using ctrl + shift + enter. The IF statement would look like this:

=IF((A1>=C:C)*(A1<=D:D),ROW(A:A),"")

Note: I did not use the AND formula here because that cannot take in arrays. But since booleans are just 1's or 0's in Excel, multiplying the criteria works just fine.

This now gives us an array containing only blanks and valid row numbers. Such that if rows 5 and 7 were both valid the array would look like:

{"","","","",5,"",7,"",...}

Now if we encapsulate that IF statement with a SMALL we can get whatever valid row we want. In this case since we just want the first valid row we can use:

=SMALL(IF((A1>=C:C)*(A1<=D:D),ROW(A:A),""),1)

Which if the first valid row is 5 then that will return 5. Incrementing the K value of the SMALL formula will allow you to grab the 2nd, 3rd, etc valid row.

Now of course since we have the row number a simple INDEX will get us the value in column E:

=INDEX(E:E,SMALL(IF((A1>=C:C)*(A1<=D:D),ROW(A:A),""),1))
3
  • 3
    Brilliant. And using LARGE() allows to find the last row matching the criteria.
    – iDevlop
    Mar 16, 2018 at 12:40
  • @chancea any reason using SMALL(exp,1) instead of MIN(exp) ?
    – iDevlop
    Apr 5, 2018 at 14:29
  • @PatrickHonorez It's just up to your development needs. If you never change it then SMALL(exp,1) and MIN(exp) are the same
    – chancea
    Apr 10, 2018 at 14:05
0

If you need to match more than one column value to retrieve a row number, that is, if two or more columns together create a unique ID you can use an array formula with MATCH as below:

MATCH(1,(A:A=J1)*(B:B=K1)*(C:C=L1),0)

where A, B, C contain the column array to be matched to retrieve the unique row number corresponding to the value in J1, K1, L1 respectively.

For a step-by-step guide, Christian Pedersen's Explainer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.