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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Isn't that formula just a long winded version of

=LARGE(IF(A1:A8<D1,A1:A8,""),1)&" - "&SMALL(IF(A1:A8>D1,A1:A8,""),1)
 
Upvote 0
I didn't notice that the board bit a chunk out of my formula, it should have said

PHP:
=LARGE(IF(A1:A8<D1,A1:A8),1)&" - "&SMALL(IF(A1:A8>D1,A1:A8),1)

and a similar afterthought

PHP:
=MAX(IF(A1:A8<D1,A1:A8)&" - "&MIN(IF(A1:A8>D1,A1:A8)

Both of which, as far as I can see, return the same results as the formula in post #30

The only reason I didn't suggest it earlier was because my interpretation of the requirement would have needed something more like

PHP:
=CHOOSE(SIGN(IFERROR(SMALL(IF(A1:A8<D1,ABS(A1:A8-D1),""),1),1E+100)-IFERROR(SMALL(IF(A1:A8>D1,A1:A8-D1,""),1),1E+100))+2,LARGE(IF(A1:A8<D1,A1:A8,""),1),LARGE(IF(A1:A8<D1,A1:A8,""),1)&" - "&SMALL(IF(A1:A8>D1,A1:A8,""),1),SMALL(IF(A1:A8>D1,A1:A8,""),1))

which works, but is a bit long, I was trying to figure out a more succinct version before posting.
 
Upvote 0
@Jasonb75
excellent formula
only missing a couple of pharentesis but works fine
thank you!



Book1
ABC
13121
2818 - 22
325
424
59
65
718
822
Foglio1
Cell Formulas
RangeFormula
C2{=MAX(IF(A1:A8))&" - "&MIN(IF(A1:A8>C1,A1:A8))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
@Jasonb75
excellent formula
only missing a couple of pharentesis but works fine
thank you!

You're welcome Gerry.

Apologies for the missing brackets, it seems to be one of my regular bad habits when I type the formula to the forum instead of copying it from excel.

When I was reading through the earlier posts in this thread I was under the impression that you only wanted the 2 numbers returned in the event of a tiebreak, but otherwise just return the closest number.

If that is the case, the long formula at the end of my earlier post does that, but it could benefit from some refinement first if you are going to use it.
 
Upvote 0

Forum statistics

Threads
1,216,499
Messages
6,131,010
Members
449,613
Latest member
MedDash99

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