Find closest number in list

nancymk

Board Regular
Joined
Jul 24, 2008
Messages
106
Let's say you have one of those M&M contests, where a bunch of people guess the number of M&Ms in a jar. In column B I have all the guesses. In cell A1 I have the right answer and in cell A2 I want a formula that will search the guesses in column B and give me the number closest to A1.

This is not for an M&M contest, but same concept :) CSE formulas welcome.

Thanks!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
use vlookup with the last parameter as true, this way it will find the nearest match without exceeding the the figure its looking for:
=Vlookup(D1,A1:A1000,1,True)
 
Upvote 0
I just realized this could result in two numbers being right, so instead if the formula could show the smallest difference by absolute value.
 
Upvote 0
Let's assume that A2:A100 contains the data/guesses, and C2 contains the target number, try...

=INDEX(A2:A100,MATCH(MIN(ABS(A2:A100-C2)),ABS(A2:A100-C2),0))

...confirmed with CONTROL+SHIFT+ENTER.
 
Upvote 0
I know how to find the answer. I was just looking for a fancy formula to populate it for me. So if the answer in A1 changes or the dataset changes it would automatically show me the new answer.
 
Upvote 0
FYI - I just added minus C2 to the end so I could get the difference. Then in another column it looks for winners based on that difference either up or down.
 
Upvote 0

Forum statistics

Threads
1,215,284
Messages
6,124,059
Members
449,139
Latest member
sramesh1024

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