Please see in the workbook , it would be easy to understand.
thanks
Please see in the workbook , it would be easy to understand.
thanks
Last edited by Sarangsood; 12-31-2011 at 07:54 AM.
=SUM(IF(($B$3:$B$23>0)*ABS($A$3:$A$23-$F$1)=MIN(ABS($A$3:$A$23*($B$3:$B$23>0)-$F$1)),$A$3:$A$23))
confirmed with CTRL + SHIFT + ENTER
same can be applied for M:N by modifying ranges accordingly.
(above would return 4800 & 4500 respectively)
thanks a lot sir. you are a genius.![]()
just one more thing @XLENT , i would also need the second closest positive number from both the ranges.
Revert to SMALL from MIN such that you can adjust "k"
=SUM(IF(($B$3:$B$23>0)*ABS($A$3:$A$23-$F$1)=SMALL(ABS($A$3:$A$23*($B$3:$B$23>0)-$F$1),2),$A$3:$A$23))
confirmed with CTRL + SHIFT + ENTER
would return 5200 & 4300 for A:B, M:N respectively
Just out of curiosity. Why does the result = 10000 when the input = 5000? I am not too familiar with the logic behind array formula, trying my best to understand it.
Good spot. In that instance there will be 2 closest matches 4800 + 5200
If OP wants just 4800 I would replace the outer SUM with MIN for first match or MAX for last match
Last edited by XLent; 12-31-2011 at 03:50 AM.
Thanks for the explanation. Really impressed with the solution you provided.
In hindsight for sake of exact match (ABS result is 0) we must insert a pre-emptive test
=MIN(IF($B$3:$B$23>0,IF(ABS($A$3:$A$23-$F$1)=SMALL(ABS($A$3:$A$23*($B$3:$B$23>0)-$F$1),1),$A$3:$A$23)))
confirmed with CTRL + SHIFT + ENTER
change k to 2 for 2nd smallest.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks