On Tue, 10 Jun 2008 01:37:01 -0700, Tom5 <(E-Mail Removed)>
wrote:
>Is there a way to condense the formula as I have 27 different cells in which
>I want to include e.g; =SUMPRODUCT((A1=Grades)+(C1=Grades)+(E1=Grades)) x 27
You could write the entire thing as a UDF, but I think it would be more useful
to write a UDF that will join non-contiguous cells into an array and then use
that UDF in a formula.
To write the UDF, <alt-F11> opens the VB Editor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Module and copy the
code below into the window that opens. The formula will accept up to 29
arguments.
Then use this **array-entered** formula (enter with <ctrl><shift><enter> ) into
some cell:
=SUM(--(ARRAYJOIN(A1,C1,C2,E1)=Grades))
The above assumes that Grades is in a vertical array. If Grades is in a
horizontal array, then you will need:
=SUM(--(ARRAYJOIN(A1,C1,C2,E1)=TRANSPOSE(Grades)))
Excel will place braces {...} around the formula if you did it correctly.
==============================
Function ArrayJoin(ParamArray CellRefs())
ArrayJoin = CellRefs
End Function
===============================
Laurent Longre has a free add-in: morefunc.xll which includes a similar
function, along with many other useful functions, but that site is "down" this
morning with a Error 403
http://xcell05.free.fr/
If available, you could download and install that add-in, and then use
=SUM(--(ARRAYJOIN(A1,C1,C2,E1)=TRANSPOSE(Grades)))
Note that ARRAYJOIN and ARRAY.JOIN are subtly different in that the first
returns a horizontal and the latter a vertical array, so the requirement for
TRANSPOSE is reversed.
The advantage of installing morefunc.xll is that it provides access to a number
of other useful functions.
--ron