Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

excel - FInd nearest value within list condition

I want to find nearest value of a cell but don't know how.

Screenshot may help you to understand the question

In my excel sheet cell B1 has a value(LIST NAME) and cell B2 has other value which is to be searched with condition. If cell B1 has value GP_42(list name) then search the value of cell B2 withing list GP_42 (D4:D13) If cell B1 has value GP_42(list name) then se[![enter image description here][2]][2]arch the value of cell B2 withing list GP_42 (E4:E13). If value doesn't match then result should be the nearest matched value. Result should be display in the cell B3.

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'll assume you want the closest value. This means that you need the absolute (ABS function) of the difference between the value in GP_42 and your search value.

In B3 as an array formula1,

=INDEX(GP_42, AGGREGATE(15, 6, ROW(GP_42)/(ABS(GP_42-B$2)=MIN(ABS(GP_42-B$2))), ROW(1:1))-ROW(GP_42)+1)

I have used ROW(1:1) to represent the number 1. This gives you the first encountered match. In my expanded examples, the third has two matches that meet the 'minimum difference' in B9 and B10. B10 is achieved by filling down. This advances ROW(1:1) to ROW(2:2) which represents 2 and gives you the second available match.

enter image description here


1 Array formulas need to be finalized with Ctrl+Shift+Enter?. If entered correctly, Excel with wrap the formula in braces (e.g. { and }). You do not type the braces in yourself. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula. Try and reduce your full-column references to ranges more closely representing the extents of your actual data. Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum. See Guidelines and examples of array formulas for more information.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...