need tricky formula

Scott R

Active Member
Joined
Feb 20, 2002
Messages
493
Office Version
  1. 365
Platform
  1. Windows
I'm looking for a non-array formula that will find the position in a list of the number closest to another number.

In A1:A6, let's say I have 1;2;7; ;8;9

The closest number to 6 would be 7, so the formula would return 3 for the 3rd position.
The closest number to 3 would be 2, so the formula would return 2 for the 2nd position.

I don't think MATCH works for me here.

Thanks!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I'm going against a lot of data--speed. But I can do that.
 
Upvote 0
Does this array formula work for you?

=SMALL(IF((MIN(ABS(A1:A6-C1))=ABS(A1:A6-C1)), ROW(A1:A6), ""), 1)

where C1 is the value you are trying to get closest to.

This doesn't take into account where you are exactly between 2 numbers. For example if you are looking for the closest number to 1.5, you have 1 and 2 the same distance apart.
 
Upvote 0

Excel 2010
ABCDE
11677
22322
37
48
59
6
6b
Cell Formulas
RangeFormula
C1{=INDEX($A$1:$A$5,MATCH(MIN(ABS(B1-$A$1:$A$5)),ABS(B1-$A$1:$A$5),0))}
D1{=INDEX($A$1:$A$5,MATCH(MIN(v(ABS(B1-$A$1:$A$5))),v(),0))}
Press CTRL+SHIFT+ENTER to enter array formulas.


The v is from Stephen Dunn about 2002; I do not know if it is faster.
 
Last edited:
Upvote 0
Thanks for the help. I ending up using the INDEX version.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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