B
Bob
I need to count the number of unique cell values in a
column, any ideas how to accomplish this?
column, any ideas how to accomplish this?
...One way
=SUM(IF(A2:A200<>"",1/COUNTIF(A2:A200,A2:A200)))
entered with ctrl + shift & enter
Or
=SUMPRODUCT((A1:A20<>"")/COUNTIF(A1:A20,A1:A20&""))
which needn't be entered as an array formula.
--
Note that if you use Excel prior to 2003 and the range is not fully used it
will return a #DIV/0! error
Harlan Grove said:...
Care is needed when critiquing my responses.
I'm running XL97 SR-2, and if I fill A1:A20 with
{1;2;3;4;5;6;7;8;9;10;9;8;7;6;5;4;3;2;1;<blank>}
the formula *above* returns 10, not #DIV/0!. Now if I had foolishly used just
=SUMPRODUCT((A1:A20<>"")/COUNTIF(A1:A20,A1:A20))
(or foolishly failed to notice that I had used the former, not the latter,
formula), then I'd get #DIV/0!. But I know better. The key is coercing the 2nd
arg to COUNTIF to be strings, thus A1:A20&"", which makes the A20 entry ""
rather than 0. Note: if A1 were 0 and A2 blank, COUNTIF(A1,A2) returns 1 because
COUNTIF coerces blank ranges in its 2nd argument to 0.
If you don't believe me, test it in an earlier version.
......
With {1;2;3;1;2;3} in A1:A6 rest are blank and NEVER used
=SUM(IF(A1:A20<>"",1/COUNTIF(A1:A20,A1:A20)))
returns 3
=SUMPRODUCT((A1:A20<>"")/COUNTIF(A1:A20,A1:A20&""))
returns
#DIV/0!
tested in excel 2000 and 2002
...Sorry Peo, but it works for me in Excel 2000.
=SUMPRODUCT((A1:A20<>"")/COUNTIF(A1:A20,A1:A20&""))
that is the working version.
Harlan Grove said:...
..
..
Oh, that bug. Fine, use
=SUMPRODUCT((A1:A20<>"")/(COUNTIF(A1:A20,A1:A20&"")+(A1:A20="")))
Longer than the SUM(IF(...)) formula, but uses one fewer nested function call
level. Your earlier caveat was ambiguous. 'Never used' is clearer than 'not
fully used'.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.