Get values from 2 ranges based on certain conditions

hsandeep

Well-known Member
Joined
Dec 6, 2008
Messages
1,213
Office Version
  1. 2010
Platform
  1. Windows
  2. Mobile
I have 2 ranges K9:W9 & K16:W16 which generates values including 0 and also “” (blank)
I need 5 formulas:

AA20=Corresponding non zero non blank number from K10:W10 corresponding to the minimum number from K16:W16 else 0

AA21=Non zero non blank number preceding the corresponding non zero non blank number from K10:W10 corresponding to the minimum number from K16:W16 with an additional condition that the minimum number is not in the cell address K16 else 0

AA22=Non zero non blank number preceding the above preceding number from K10:W10 with an additional condition that the minimum number is not in the cell address K16 or L16 else 0

AA23= Non zero non blank number succeeding the corresponding non zero non blank number from K10:W10 corresponding to the minimum number from K16:W16 with an additional condition that the minimum number is not in the cell address W16 else 0

AA24= the minimum number from K16:W16

How to accomplish?
Thanks in advance
10​
22​
30​
4​
55
66
100
111
2​
99​
10​
20​
33​
1​
2​
3​
4​
40​
50​
-66
55​
-60​
-50​
-12​
12​
66​
Corresponding
100
Preceeding
66
Preceeding 2
55
Suceeding
111
Reference
-66
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Do these formulas work for you?
NOTE: You need to commit to the cell with the CNTL-SHFT-ENTR keystroke (CSE).

Book1
KLMNOPQRSTUVWXYZAAAB
910223045566100111299102033
10
1612344050-6655-60-50-121266
17
18
19
20Corresponding100100
21Preceeding6666
22Preceeding 25555
23Suceeding111111
24Reference-66
Sheet1
Cell Formulas
RangeFormula
AB20AB20=IFERROR(INDEX($K$9:$W$9,1, SUM((($K$16:$W$16)=MIN($K$16:$W$16))* (COLUMN($K$16:$W$16)-COLUMN($K$16)+1))),0)
AB21AB21=IFERROR(INDEX($K$9:$W$9,1, SUM((($K$16:$W$16)=MIN($K$16:$W$16))* (COLUMN($K$16:$W$16)<>COLUMN($K$16))* (COLUMN($K$16:$W$16)-COLUMN($K$16)+1))-1),0)
AB22AB22=IFERROR(INDEX($K$9:$W$9,1, SUM((($K$16:$W$16)=MIN($K$16:$W$16))* ( (COLUMN($K$16:$W$16)<>COLUMN($K$16))+ (COLUMN($K$16:$W$16)<>COLUMN($L$16))-1 ) * (COLUMN($K$16:$W$16)-COLUMN($K$16)+1))-2),0)
AB23AB23=IFERROR(INDEX($K$9:$W$9,1, SUM((($K$16:$W$16)=MIN($K$16:$W$16))* (COLUMN($K$16:$W$16)<>COLUMN($W$16))* (COLUMN($K$16:$W$16)-COLUMN($K$16)+1))+1),0)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
=IFERROR(INDEX($K$9:$W$9,1, SUM((($K$16:$W$16)=MIN($K$16:$W$16))* (COLUMN($K$16:$W$16)<>COLUMN($W$16))* (COLUMN($K$16:$W$16)-COLUMN($K$16)+1))+1),0)
awoohaw

Your first 3 formulas work well. But the 4th formula for getting the succeeding number doesn’t work when the minimum number from K16:W16 is in the cell address W16 i.e. the last cell (right most cell) of the range K16:W16. In such case, answer should be 0
 
Upvote 0
How about these non-array formulas?

Book1
ZAA
20Corresponding100
21Preceeding66
22Preceeding 255
23Suceeding111
24Reference-66
Sheet4
Cell Formulas
RangeFormula
AA20AA20=INDEX(K9:W9,MATCH(AA24,K16:W16,0))
AA21AA21=IFERROR(INDEX(K9:W9,1/(1/(MATCH(AA24,K16:W16,0)-1))),0)
AA22AA22=IFERROR(INDEX(K9:W9,1/(1/(MATCH(AA24,K16:W16,0)-2))),0)
AA23AA23=IFERROR(INDEX(K9:W9,MATCH(AA24,K16:W16,0)+1),0)
AA24AA24=MIN(K16:W16)
 
Upvote 0
try these:

Book1
KLMNOPQRSTUVWXYZAAAB
910223045566100111299102033
16-70-72-714-6850-6655-60-50-12-6766
17
18
19
20Corresponding22
21Preceeding10
22Preceeding 20
23Suceeding30
24Reference-72
Sheet1
Cell Formulas
RangeFormula
AB20AB20=IFERROR(INDEX($K$9:$W$9,1, SUM((($K$16:$W$16)=MIN($K$16:$W$16))* (COLUMN($K$16:$W$16)-COLUMN($K$16)+1))),0)
AB21AB21=IFERROR(INDEX($K$9:$W$9,1, SUM((($K$16:$W$16)=MIN($K$16:$W$16))* (COLUMN($K$6:$W$16)>COLUMN($K$16))* (COLUMN($K$16:$W$16)-COLUMN($K$16)+1))-1),0)
AB22AB22=IFERROR(INDEX($K$9:$W$9,1, SUM((($K$16:$W$16)=MIN($K$16:$W$16))* (COLUMN($K$6:$W$16)>COLUMN($L$16))* (COLUMN($K$16:$W$16)-COLUMN($K$16)+1))-2),0)
AB23AB23=IFERROR(INDEX($K$9:$W$9,1, SUM((($K$16:$W$16)=MIN($K$16:$W$16))* (COLUMN($K$16:$W$16)-COLUMN($K$16)+1))+1),0)
AA24AA24=MIN(K16:W16)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Solution
You're welcome. I'm sure there are more concise formulas that do the same thing. But, this works, so great.

Best Wishes.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,680
Members
449,116
Latest member
HypnoFant

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