Reputation: 1498
I have a workbook with 2 worksheets, Sheet1
and Sheet2
.
Sheet1
has a value (product code) to look up, and an empty cell to fill:
A B
A100
A200
B150
C3AB
Sheet2
has a bunch of product codes and costs:
A B
A100 35
A100 14
A100 0
A200 10
A200 12
etc, etc, etc
I'm using the following formula in Sheet1 B1 to find the MIN matching value from Sheet2:
=MIN(IF(Sheet2!$A$1:$A$5=A1,Sheet2!$B$1:$B$5))
How can I also exclude returning a match of 0? In the case of product A100, I would want to return the lowest non-zero match which would be 14.
Upvotes: 3
Views: 7780
Reputation: 582
Would it be any faster if you add column C on Sheet 1 and fill it with:
=IF(B1=0," ",B1)
Then your original formula entered as a matrix would work referencing column C instead:
=MIN(IF(Sheet2!$A$1:$A$5=A1,Sheet2!$C$1:$C$5))
Can anyone comment on the speed of adding another column? It sounds like the sheet has up to ~20000 rows.
Upvotes: 2
Reputation: 2530
Array formula:
{=SMALL(IF(Sheet2!$B$1:$B$5<>0;IF(A3=Sheet2!$A$1:$A$5;Sheet2!$B$1:$B$5;"");"");1)}
Shift-Ctrl-Enter in formula window to insert, curled brackets are inserted by Excel, not by a user.
MIN
behaved strangely, issuing 0
also for non-numeric values in the array. SMALL
was used instead, giving #NUM!
error for non-existing references.
Example spreadsheet: http://www.bumpclub.ee/~jyri_r/Excel/MInimal_value_excluding_0.xls
Upvotes: 1
Reputation: 2275
Try submitting this as an array formula in B1
untested
=MIN(IF(((Sheet2!$A$1:$A$5=A1)*(Sheet2!$B$1:$B$5>0))>0,Sheet2!$B$1:$B$5))
I think This Will work
Upvotes: 2
Reputation: 1528
AFAIK: Either use VBA to loop through the values, or:
create another column using a formula similar to =IF(a1=0,"",A1)
(copied down for each value in column A). Then you can use the min function on this column.
HTH
Upvotes: 0