简体   繁体   English

在Excel(含非数值栏位)的值范围中寻找最接近0的值

[英]Find closest value to 0 in range of values in Excel (with non-numeric fields)

I have a range of cells in Excel with various positive and negative numbers. 我在Excel中有一系列带有不同正数和负数的单元格。 The value of the cell is determined by an IF formula, and some of the cells in the range have no value (""). 单元格的值由IF公式确定,该范围内的某些单元格没有值(“”)。

I need to find the absolute value of the nearest cell to 0. So if I had a list of -10,-5,-1, 3, 6, and "": I need to get a result of 1. 我需要找到最接近于0的单元格的绝对值。因此,如果我有一个-10,-5,-1、3、6和“”列表:我需要得到1的结果。

I've tried multiple approaches but the fact that I have non-numeric cells seems to be an issue which is causing errors. 我尝试了多种方法,但是我拥有非数字单元格的事实似乎是导致错误的问题。

What I've tried: 我试过的

{=Min(ABS(A1:D10))} , where I press Ctrl-Shift-Enter (returns an error because of non-numerics) {=Min(ABS(A1:D10))} ,在这里按Ctrl-Shift-Enter(由于非数字而返回错误)

{=IF(MAX(D3:D22)<=0,-1,IF(MIN(ABS(D3:D22))=MIN(ABS(IF(D3:D22>0,D3:D22,MAX(D3:D22)))),1,-1))*MIN(ABS(D3:D22))} , where I press Ctrl-Shift-Enter (returns an error because of non-numerics) {=IF(MAX(D3:D22)<=0,-1,IF(MIN(ABS(D3:D22))=MIN(ABS(IF(D3:D22>0,D3:D22,MAX(D3:D22)))),1,-1))*MIN(ABS(D3:D22))} ,在此按Ctrl-Shift-Enter(由于非数字而返回错误)

{=IF(OR((D3:D22)>0),MIN(ABS(D3:D22)),-MIN(ABS(D3:D22)))} , where I press Ctrl-Shift-Enter (returns an error because of non-numerics) {=IF(OR((D3:D22)>0),MIN(ABS(D3:D22)),-MIN(ABS(D3:D22)))} ,在这里按Ctrl-Shift-Enter(返回错误由于非数字)

=MIN(ABS(IF(ISNUMBER(D3:D22),D3:D22,9999)))

This is an array formula and must be confirmed with Ctrl + Shift + Enter 这是一个数组公式,必须通过Ctrl + Shift + Enter进行确认

should do the trick 应该可以

or better use: 或更好地使用:

=INDEX(D3:D22,MATCH(MIN(IF(ISNUMBER(D3:D22),ABS(D3:D22))),ABS(D3:D22),0))

This is an array formula and must be confirmed with Ctrl + Shift + Enter 这是一个数组公式,必须通过Ctrl + Shift + Enter进行确认

doesn't care about text or empty cells but having 0 as number will count... also negative numbers will be negative (if you allways want positive you need to ABS the whole formula... 不在乎文本或空白单元格,但数字为0会计数...负数也将为负数(如果您始终想要正数,则需要对整个公式进行ABS吸收...

If you have an upper bound, say 10^9, on what the min is you can do: 如果您有一个最小值的上限,例如10 ^ 9,则可以执行以下操作:

{=MIN(ABS(IF(ISNUMBER(D3:D22),D3:D22,10^9)))}

If you find it problematic to make any assumptions about what the min is, note that it is certainly less than 1 + the absolute value of the maximum number, so you could use: 如果您发现对最小值表示什么有疑问,请注意该值肯定小于1 +最大值的绝对值,因此可以使用:

{=MIN(ABS(IF(ISNUMBER(D3:D22),D3:D22,1+ABS(MAX(D3:D22)))))}

I'm posting this only because it worked for me before the other users came in with their answers. 我之所以发布此信息,仅是因为它对我有用,然后其他用户才回答他们。 I'll still accept one of their answers rather than this. 我仍然会接受他们的答案之一,而不是这个。

=MIN(IF(D3:D22>0,D3:D22,ABS(D3:D22)))

And of course I had to press Ctrl + Shift + Enter to get this to work. 当然,我必须按Ctrl + Shift + Enter才能使它起作用。

Here is how one finds the number closest to zero when the values are not in contiguous cells? 当值不在连续的单元格中时,如何找到最接近零的数字呢? (ie, not in a 'range') For example, a1 , b5 and f15 contain the values -3, 4 and -5. (即不在“范围”内)例如, a1b5f15包含值f15和-5。 The formula should return the value -3. 该公式应返回值-3。

Tom Ogilvy at https://www.atlaspm.com/toms-tutorials-for-excel/ answered the question: https://www.atlaspm.com/toms-tutorials-for-excel/的汤姆·奥格维(Tom Ogilvy)回答了以下问题:

For the specific question you asked, this would return -3 对于您提出的具体问题,它将返回-3

=INDEX(CHOOSE({1,2,3},A1,B5,F15),MATCH(MIN(ABS(CHOOSE({1,2,3},A1,B5,F15))),ABS(CHOOSE({1,2,3},A1,B5,F15)),0))

entered with Ctrl + Shift + Enter . 使用Ctrl + Shift + Enter输入 You can adjust the CHOOSE({1,2,3},A1,B5,F15) (which replaces the C7:C20 in the original formula) to include more cells. 您可以调整CHOOSE({1,2,3},A1,B5,F15) (它将替换原始公式中的C7:C20 )以包括更多单元格。 For example if I wanted to add Z20 and AA4 I could use CHOOSE({1,2,3,4,5},A1,B5,F15,Z20,AA4) . 例如,如果我想添加Z20AA4 ,则可以使用CHOOSE({1,2,3,4,5},A1,B5,F15,Z20,AA4) Each cell would need to be listed individually. 每个单元格都需要单独列出。 so you could not have CHOOSE({1,2},A1,B5:B20) 因此您无法CHOOSE({1,2},A1,B5:B20)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM