How to count number of distinct values in a range?

I've got a large table that is already organized using filters etc. I'd like to add a summary underneath certain columns that contain the number of distinct values in that column.

There's no function =COUNTDISTINCT(A2:A100) so what can I do instead? (Excel 2003)

I can't exactly use answers to this similar question because I don't want to modify the table or the filtering. I need an addition in the worksheet, not a modification.


=SUMPRODUCT((A2:A100 <> "")/COUNTIF(A2:A100,A2:A100 & ""))

will do it without having to use an array formula.


I found a solution here which seems to be an incredible roundabout way to solve it. But hey, it works...

=SUM(IF(COUNTIF(A2:A100,A2:A100)=0, "", 1/COUNTIF(A2:A100,A2:A100)))

and then press Ctrl+Shift+Enter. Pressing only Enter will give the wrong result.