View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
vezerid
 
Posts: n/a
Default Help me write a function please?

SUMPRODUCT(A1:A10, B1:B10) will essentially do:

sum = 0
for i = 1 to 10
sum = sum + A(i)*B(i)
next i

For your purposes, the same example as above could be written as
SUMPRODUCT(A1:A10*B1:B10)

So, as you can see, it makes a pairwise multiplication of arrays.
Examine now the three arrays multiplied:
They are virtual arrays. The sub-expression, for example,
(B2:B200=C1)
will produce a computed array of TRUE or FALSE, depending on whether
B(i)=C1. The -- turns T/F into a number (1/0).
So, as you see, for each row, we multiply 1/0 with 1/0 with the amount
in column C:C. If both are 1 then the corresponding row in C:C will be
included in the summation. In this way multiplication essentially
becomes conjunction (AND) in a logical expression.
I hope this is clear enough to show you the principle.

Only SUMPRODUCT behaves this way. For example, if you try
SUM(A1:A100*B1:B100)
you would need to array-enter it, i.e. by pressing Shift+Ctrl+Enter.
Thus, the formula I suggested could have been written with SUM()
instead of SUMPRODUCT(), everything else being the same, but you would
need this key combination for it to work.

I hope this helps a bit in understanding the logic.

And no, I don't want you to change any format, just the numbers in the
formula. Replace for example A200 with A500 if you have more rows.

HTH
Kostis Vezerides