VLookup next highest value

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Assuming I have data like this in cells A1 through to B5:

10 Apple
20 Orange
30 Pear
40 Plum
50 Watermelon

I want a formula so if I enter 10, it returns Apple and if I enter 20 it will return Orange.

That formula would be:

Code:
=VLookup(J1,A1:B5,2,False)

where J1 is the value to lookup.

However, I want a variant of this, in that if I enter 15, I want to return Orange.

but the following formula returns Apple:

Code:
=VLookup(J1,A1:B5,2,True)

The following taken from here:

Code:
https://www.extendoffice.com/documents/excel/2704-excel-vlookup-next-largest-value.html

does indeed work:

Code:
=INDEX(B1:B5,MATCH(J1,A1:A5)+(LOOKUP(D5,A1:A5)<>J1))

but if I enter a value less than 10 or greater than 50, I get #N/A and /REF! respectively.

How can I amend the formula for my needs?

Thanks
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
but if I enter a value less than 10 or greater than 50
What result do you expect if you enter a value greater than 50? There is no value greater than 50 in the list so in theory the error for that is correct based on the rest of your logic.
Excel Formula:
=IFERROR(INDEX($B:$B,AGGREGATE(15,6,ROW($A$2:$A$5)/($A$2:$A$5>=J1),1)),"No Match")
 
Upvote 0
What result do you expect if you enter a value greater than 50? There is no value greater than 50 in the list so in theory the error for that is correct based on the rest of your logic.
Excel Formula:
=IFERROR(INDEX($B:$B,AGGREGATE(15,6,ROW($A$2:$A$5)/($A$2:$A$5>=J1),1)),"No Match")
I understand it's returning the correct result but I wanted to know if it can be amended so that it'll return Watermelon.

My quick fix was to change the 50 in the table to a very large number and add a 0 before 10 and return "no fruit".
 
Upvote 0
In that case, try
Excel Formula:
=IFERROR(INDEX($B:$B,AGGREGATE(15,6,ROW($A$2:$A$5)/($A$2:$A$5>=J1),1)),$B$5)

Base on your original question, anything below 10 should return 10 as the next highest value, which is what this one does. I've amended the last bit so that it returns the last thing in the list (B5) if the value exceeds the max in column A.
 
Upvote 0
In that case, try
Excel Formula:
=IFERROR(INDEX($B:$B,AGGREGATE(15,6,ROW($A$2:$A$5)/($A$2:$A$5>=J1),1)),$B$5)

Base on your original question, anything below 10 should return 10 as the next highest value, which is what this one does. I've amended the last bit so that it returns the last thing in the list (B5) if the value exceeds the max in column A.
Thanks, that's great.
 
Upvote 0

Forum statistics

Threads
1,224,905
Messages
6,181,662
Members
453,059
Latest member
jkevin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top