Find closest number to zero

raihnman

Board Regular
Joined
Nov 5, 2002
Messages
99
Hey people,

I have a coulmn of positive and negative numbers. Some of the numbers are zero too. How do I find the number that is closest to zero? This number could be positive or negative.

Thanks,

Raihnman
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
use the ABS() function

If column A has your values, use column B to evaluate. E.g.:
B1 =if(A1=0,"z",ABS(0-A1))
Then sort on Column B, ascending
 
Upvote 0
Book1
ABCD
16
2-3-1
35
4-1
54
62
73
8-1
96
104
111
126
13-3
146
150
16
Sheet1


The formula used is...

=INDEX(A1:A15,MATCH(SMALL(INDEX(ABS(A1:A15),0,1),COUNTIF(A1:A15,0)+1),INDEX(ABS(A1:A15),0,1),0))

Of course the positive value 1 in the range is equally correct. The MATCH bit will pick out either -1 or 1, that's whichever occurs early in the current range of values.
 
Upvote 0
Thanks for everyone's help. I appreciate all the inputs.

Aladin, your code is great. Thanks for taking the time to solve my problem so eloquently.

Raihnman
 
Upvote 0
This formula is almost perfect for something I am working on, but what if zero would be the best number for me to have returned? How can I update this formula (or write a new one) that would get me the closest to zero, including zero?
Thanks in advance!
 
Upvote 0
This formula is almost perfect for something I am working on, but what if zero would be the best number for me to have returned? How can I update this formula (or write a new one) that would get me the closest to zero, including zero?
Thanks in advance!

We need to remove the CountIf bit and change Small to Min...

=INDEX(A1:A15,MATCH(MIN(INDEX(ABS(A1:A15),0,1)),INDEX(ABS(A1:A15),0,1),0))
 
Upvote 0
Hi Aladin,
I found that I have some rows of data that are all negative numbers, some have all positive, and some have a mixture. How can I update this formula to give me the number closest to zero, regardless of +/-?
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,600
Members
452,927
Latest member
whitfieldcraig

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