I think you were right to look at INDEX
and MATCH
. See if the following does what you intended:
The formula looks for a "match" with no type specified - that is, it will find the last value less than the value you are looking for (assuming that the values are sorted). You add 1
to get the value you intended (the first value not less than == the value that is greater or equal). It then uses INDEX
to find the corresponding value (I used letters) in the row C1:F1
, and returns that value in cell B2
. If this is not what you intended, please clarify... it's what I understood from the question.
Obviously, if you need to repeat this formula many times, then write it in B2 as follows:
=INDEX($C$1:$F$1, MATCH(A2, C2:F2)+1)
and double-click the little "drag handle" in the bottom right hand corner to make it replicate to all rows in column B (whilst correctly preserving the absolute / relative addressing)
EDIT @Simoco pointed out that my formula would fail if the first value is larger than the criterion (since that means there is "no value smaller than"). You can tweak it with
=IFERROR(INDEX($C$1:$F$1, MATCH(A2, C2:F2)+1),$C$1)
That's a really cool function that says "if the thing gives an error, use this other value instead". This does assume that there is at least one value that meets the criterion; if it is possible that none of the values meet the criterion you may need to be even smarter:
=IFERROR(INDEX($C$1:$F$1, MATCH(A2, C2:F2)+1),IF(MAX(C2:F2)>A2,$C$1, "No match"))
That last error message can be whatever you want it to be, obviously.