Question

enter image description here

What I need is

  1. B column values (red) should be calculated by Excel without VBA
  2. A column (Conf. Level) has the criteria values per row
  3. In each row, B column's related cell must print the 1st same row cell's column title that is >= than related criteria value

For example:

B2 prints 0 since C2 is the 1st value that is >= than A2

B3 prints 2 since E3 is the 1st value that is >= than A3

I've read the Q&A in this site with excel, indexing, match tags and tried something but I couldn't achieve more than #N/A. I've also read Microsoft excel help pages for Index() and Match() functions.

I have tons of rows in real case (not only 3 data rows).

Was it helpful?

Solution

Try this one in B2:

=SMALL(IF(C2:F2>A2,$C$1:$F$1),1)

This is an array formula, so type the formula then press CTRL+SHIFT+ENTER. Curly brackets will automatically appear at the start and end of the formula. Then drag formula down.

If there is no value greater than A2, SMALL returns #NUM!

OTHER TIPS

I think you were right to look at INDEX and MATCH. See if the following does what you intended:

enter image description here

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top