Formula for closest value

Robandemmy

Board Regular
Joined
Jul 16, 2018
Messages
65
I have a table somewhat like:

Red 20
Red 30
Black 30
Black 20
Red 25
Red 15
Black 40

Closest to: 23

I want to write a formula that will return the value in column B that closest to 23 when column A equals Red. In this case 25.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try...

A2:F8

Red20Red2325
Red30
Black30
Black20
Red25
Red15
Black40

<tbody>
</tbody>

F2, confirmed with CONTROL+SHIFT+ENTER...

=INDEX(B2:B8,MATCH(SMALL(IF(A2:A8=D2,ABS(B2:B8-E2)),1),IF(A2:A8=D2,ABS(B2:B8-E2)),0))

Hope this helps!
 
Upvote 0
Thanks for the suggestion!

Unfortunately it doesn't work for me...I get an #N/A error returned

Red20Red23#N/A
Red30
Black30
Black20
Red25
Red15
Black40

<tbody>
</tbody>
 
Upvote 0
Hello,

Domenic's formula is an Array Formula ...

Instead of the Enter key ... you need to use simultaneously the three keys : Control Shift Enter ...

Hope this will help
 
Upvote 0
That worked great. However, I thought I would be able to edit/add to it's functionality. So I have this table:

NamePickScore
MikeRed10
JackBlack20
Kevin
Red30
RobBlack40
TomBlack20
MarkBlack30
MattRed23
JohnBlack33
Todd BRed40
Shane MRed50
Joey BRed30
Lloyd DBlack20
LeonardBlack26
RESULTRed35

<tbody>
</tbody>

This data is entered manually, I want to populate another table shown below:

NameResult
MikeN
JackN
Kevin
Y
RobN
TomN
MarkN
MattN
JohnN
Todd BN
Shane MN
Joey BN
Lloyd DN
LeonardN
LeonardN

<tbody>
</tbody>

So I want to put a formula in column B which looks at first table and for the name with the closest result to result in a "Y", otherwise "N". In this case Kevin received the "Y" (For having "red" and of those that also had "red", his 30 was closest to 35) I hope that makes sense...
 
Upvote 0
Try:


ABCDEFGH
1NamePickScoreNamePick
2MikeRed10MikeRedN
3JackBlack20JackBlackN
4KevinRed30KevinRedY
5RobBlack40RobBlackN
6TomBlack20TomBlackN
7MarkBlack30MarkBlackN
8MattRed23MattRedN
9JohnBlack33JohnBlackN
10Todd BRed40Todd BRedY
11Shane MRed50Shane MRedN
12Joey BRed30Joey BRedY
13Lloyd DBlack20Lloyd DBlackN
14LeonardBlack26LeonardBlackN
15
16RESULTRed35

<tbody>
</tbody>
Sheet5

Array Formulas
CellFormula
G2{=IF(AND(B2=$B$16,ABS(C2-$C$16)=MIN(IF($B$2:$B$14=$B$16,ABS($C$16-$C$2:$C$14)))),"Y","N")}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>





There are multiple Ys in this example, since there are multiple people with a difference of 5.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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