How do I find a closest number in Excel and bring back a corresponding cell?

余生颓废 提交于 2019-12-13 18:42:35

问题


Row 1 : YORK / LEEDS / WINDSOR / CHESHIRE

Row 2 : 10 / 8 / 6 / 9

So I want to find the closest match to York in the other data across each row, and bring back the title of the closest match.

So the answer i want to bring back for row 2 (York = 10) is "CHESHIRE" as 9 is the closest to 10.

Thank you!


回答1:


If your data is in A1:D2 try this "array formula"

=INDEX(B$1:D$1,MATCH(MIN(ABS(A2-B2:D2)),ABS(A2-B2:D2),0))

confirmed with CTRL+SHIFT+ENTER

If 2 or more values are equally close then the match will be with the first one from the left.....




回答2:


There are reasons for avoiding array formulas, see e.g.:

  • A Microsoft page (look for "Disadvantages of using array formulas").

  • This.

If you care about this, and prefer not to use array formulas, the following works.

=INDEX(B$1:D$1,MATCH(MIN(INDEX(ABS($B2:$D2-$A2),0)),INDEX(ABS($B2:$D2-$A2),0),0))

Credits to Brad and barry houdini, who helped solving this question.



来源:https://stackoverflow.com/questions/20072065/how-do-i-find-a-closest-number-in-excel-and-bring-back-a-corresponding-cell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!