Formula for closest number

GerryZ

Well-known Member
Joined
Jul 4, 2014
Messages
1,224
Office Version
  1. 365
Platform
  1. Windows
Hello everybody
I need a formula in D2 that find th closest number (criteria number in D1)
esemple if in D1 is 9 should give me back 11 but if in D2 i digit 5 it should give me 4
thank yu for your help



Book1
ABCD
11CRITERIA6
24RESULT5
35
49
511
615
718
819
Foglio1
 
This finds nearest +/- but if an actual match it will return that!
Array - CSE

=INDEX(A1:A16,MATCH(MIN(ABS(A1:A16-D1)),ABS(A1:A16-D1),0))
Hello Gaz Nice formula but still not right
because I dont need the same number of the criteria
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
OK this will find nearest +/-, if it find an actual match, it will return the nearest BELOW, don't know if that is acceptable?
Array formula
=IF(MATCH(D1,A1:A16,0),VLOOKUP(D1-1,A1:A16,1),INDEX(A1:A16,MATCH(MIN(ABS(A1:A16-D1)),ABS(A1:A16-D1),0)))
 
Upvote 0
Oops made a mistake, try
Array
=IFERROR(IF(MATCH(D1,A1:A16,0),VLOOKUP(D1-1,A1:A16,1)),INDEX(A1:A16,MATCH(MIN(ABS(A1:A16-D1)),ABS(A1:A16-D1),0)))
 
Upvote 0
Hi ,

Try the following array formula , to be entered using CTRL SHIFT ENTER :

=INDEX(List,MATCH(MIN(ABS(IF(List<>CRITERION,List) - CRITERION)),ABS(IF(List<>CRITERION,List) - CRITERION),0))

Narayan
 
Upvote 0
Oops made a mistake, try
Array
=IFERROR(IF(MATCH(D1,A1:A16,0),VLOOKUP(D1-1,A1:A16,1)),INDEX(A1:A16,MATCH(MIN(ABS(A1:A16-D1)),ABS(A1:A16-D1),0)))
thanks Gaz
till now this is the best solution even if is not 100% correct because in case of same number it returs the belowe number but in some cases the right number is the above number
 
Upvote 0
Hi ,

Try the following array formula , to be entered using CTRL SHIFT ENTER :

=INDEX(List,MATCH(MIN(ABS(IF(List<>CRITERION,List) - CRITERION)),ABS(IF(List<>CRITERION,List) - CRITERION),0))

Narayan
woooooowwww!!!NARAYANK991 this worrks fine!!!!!
thank you so Much iwill use yur formula
Also a big thank you to Gaz which is very helpful
 
Upvote 0
Nice, that looks like it works.

Hi ,

Try the following array formula , to be entered using CTRL SHIFT ENTER :

=INDEX(List,MATCH(MIN(ABS(IF(List<>CRITERION,List) - CRITERION)),ABS(IF(List<>CRITERION,List) - CRITERION),0))

Narayan
 
Upvote 0
@INGOLF
in this case both 4 and 6

The question you initially posed requires, control+shift+enter...
Rich (BB code):

=INDEX(A1:A8,MATCH(MIN(ABS(A1:A8-D1)),ABS(A1:A8-D1),0))
The remark implies a different question with a two component answer...

a) Control+shift+enter, not just enter:
Rich (BB code):

=INDEX(A1:A5,MATCH(MIN(ABS(IF(A1:A5 < D1,A1:A5-D1,9.99999999999999E+307))),
    ABS(A1:A5-D1),0))
b) Control+shift+enter, not just enter:
Rich (BB code):

=INDEX(A1:A7,MATCH(MIN(ABS(IF(A1:A7 > D1,A1:A7-D1,9.99999999999999E+307))),
    ABS(IF(A1:A7>D1,A1:A7-D1)),0))
 
Upvote 0
@Aladin great
in case I need both number?
example criteria D1 I've 4 and in the list I've 1-3-4-5-9-21
i want both 3 and 5 because they both have the same distance from 4
hope is clear
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,047
Members
449,206
Latest member
Healthydogs

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