# Thread: Solved: SUMPRODUCT (or array formula?) question

1. ## Solved: SUMPRODUCT (or array formula?) question

Hi fellows,

Having trouble trying to make a formula work. Could you help me?
Attached workbook is simple and self-explanatory.

*If possible, do not use an auxiliar row to make the desired formula to work.

Thank you.

2. in H12 you can put
=SUM(VLOOKUP(C\$15,\$B\$6:\$C\$7,2)*C12,VLOOKUP(D\$15,\$B\$6:\$C\$7,2)*D12,VLOOKUP(E\$ 15,\$B\$6:\$C\$7,2)*E12)
you can then drag that formula down

there is probably a way to do this as an array formula but I'm not sure how....

3. Here's one way

=SUMPRODUCT(C12:E12,N(OFFSET(\$C\$6,MATCH(\$C\$15:\$E\$15,\$B\$6:\$B\$7,0)-1,0)))

4. BTW, that would have been a nice one to put in our new SUMPRODUCT sub-forum

5. I think so too!

6. Thank you guys, and thanks for moving thread.

I chose xld's formula because my real table is bigger and has a lot of "Quantity" columns.

xld: why does the formula doesn't work if I take the 'N' function?

7. One more question:
Occasionaly, some cell of row 15 will be at blank. If this happens, I get an error from the formula. Is there any way to fix it?
I tried using IF/ISERROR and also IF/C15:E15<>"" as an array formula with no success.

Edit: Assume that when that cell in row 15 is blank, the value to multiply the elements in the column is 0.

8. How about a simple workaround; force a substitute if a letter is deleted.

9. I did it!

The array formula is:
=SUMPRODUCT(C12:E12,IF(ISERROR(N(OFFSET(\$C\$6,MATCH(\$C\$15:\$E\$15,\$B\$6:\$B\$7,0)-1,0))),0,N(OFFSET(\$C\$6,MATCH(\$C\$15:\$E\$15,\$B\$6:\$B\$7,0)-1,0))))

The only bad thing is (I think) that the CPU cost of this formula is higher than if I used a hidden auxiliar row, like rule #9 at this link: http://www.ozgrid.com/forum/showthread.php?t=76234, or like a hidden LOOKUPV at row 16 bringing the desired letter value.

I got one more challenge... the column at my database where I'm using this formula is filled by merged cells, and Excel does not accept array formulas in merged cells.

10. I managed to do a better formula than the one above (it's an array formula too):
=SUMPRODUCT(C12:E12,IF(\$C\$15:\$E\$15="",0,N(OFFSET(\$C\$6,MATCH(\$C\$15:\$E\$15,\$B\$ 6:\$B\$7,0)-1,0))))

As for the problem of the merged cells array formula, I noticed that merged cells can have an array formula by doing this:

1 - Unmerge the cells where you want to put the formula;
2 - Put the array formula on the single top cell;
3 - Merge again as desired;
4 - Copy the formula to the others cells.

11. If you need to CSE it, there is no pint in SUMPRODUCT, you might just as well SUM it

=SUM((C12:E12)*(IF(\$C\$15:\$E\$15="",0,N(OFFSET(\$C\$6,MATCH(\$C\$15:\$E\$15,\$B\$6:\$B \$7,0)-1,0)))))

I got one more challenge... the column at my database where I'm using this formula is filled by merged cells, and Excel does not accept array formulas in merged cells.
Don't use merged cells, they are more trouble than they are worth.

xld: why does the formula doesn't work if I take the 'N' function?
Because OFFSET returns cell references, we need the values, so with use N to force them to values.

14. Originally Posted by xld
Don't use merged cells, they are more trouble than they are worth.
Could not convince my boss about that.

15. Originally Posted by xld
If you need to CSE it, there is no pint in SUMPRODUCT, you might just as well SUM it

=SUM((C12:E12)*(IF(\$C\$15:\$E\$15="",0,N(OFFSET(\$C\$6,MATCH(\$C\$15:\$E\$15,\$B\$6:\$B \$7,0)-1,0)))))
I'm sorry, but what is CSE?

Anyway, thanks for all explanation.

I'm sorry, but what is CSE?

Anyway, thanks for all explanation.