Search code examples
google-sheetsgoogle-sheets-formula

Return line after looking up for a value in a range of values


I need help to get the following result. Explanation below image:

Excel Spredsheet

The only editable cell is A2.

When I insert a value in A2, C2 prints the corresponding line from the table A5:C11.

E.g., if I put any number between A7 and B7 (33-40), it should print line 7 in C2. For instance, if I put 35, it returs 33 40 R$ 4.069,80.

If I change the value in A2 to, let's say, 55, cell C2 returns 51 60 R$ 6.300,00 (because 55 is in the 51-60 range).

I've tried without success using VLOOKUP and XLOOKUP. I dunno what to do from now on.


Solution

  • Since you wanted a separate answer:

    When typing a formula, there are optional parameters which can sometimes be helpful. In this case, the Match mode:

    enter image description here

    I'd prefer the slightly adjusted formula so you get a warning when the target number doesn't fall between any range

    =IF(OR(A2<A6,B11<A2),"OUT OF BOUNDS",XLOOKUP(A2,A6:A11,A6:C11,"",-1))

    If the ranges aren't sorted like you have them now, you can opt for the min/max bounds like user11222393 has them.

    enter image description here