See if this helps with the understanding:
Using this data:
A1: DUCK
B1: DUCK
C1: (blank)
D1: CAT
and the formula =SUMPRODUCT((A1:D1<>"")/COUNTIF(A1:D1,A1:D1&""))
The (A1:D1<>"") part tests if each cell in A1:D1 is not blank. Each
non-blank returns a 1, each blank returns a zero. (Actually, it returns TRUE
and FALSE, but Excel converts them to 1's and 0's)
Consequently, the example data would return this array: 1,1,0,1
Next, the COUNTIF(A1:D1,A1:D1&"") section counts how many times it finds
each cell's value in the range A1:D1.
Our data would return the array: 2,2,1,1
So the resulting array divisions would match the items from the first array
with the items in the second array to get: 1/2, 1/2, 0/2, 1/1
The SUMPRODUCT function adds all of those values and is only really
necessary in this example to force Excel to perform array calculations. In
this case, the total equals 2 unique items.
You could skip the SUMPRODUCT function and use this formula instead:
=SUM((A1:D1<>"")/COUNTIF(A1:D1,A1:D1&""))
...but you'd need to confirm that array formula by holding down the [Ctrl]
and [Shift] keys when you press [Enter]. For many people, that's too obscure
a combination to remember only occaissionally. Hence, I generally prefer the
SUMPRODUCT function approach.
I hope that helps?
***********
Regards,
Ron
> This works perfectly - sorry, I now see how I could have just made the column
> to row adjustment myself.
[quoted text clipped - 45 lines]
> > > > > Thanks very much for any help.
> > > > > Daniel
Daniel Bonallack - 21 Nov 2005 20:56 GMT
That's really clever - thanks for taking the time to explain.
As you've probably guessed, the actual example I'm applying this to isn't
about ducks and cats. My problem is that it's not actually A1, B1, C1, and
D1 that I'm testing, but rather G1, M1, S1 and Z1.
Can the same formula work across this range (to put the answer in AA1)?
Thanks again - if you've moved on to help others and feel this thread is at
close, I'll quite understand
Daniel
> See if this helps with the understanding:
>
[quoted text clipped - 84 lines]
> > > > > > Thanks very much for any help.
> > > > > > Daniel