views:

660

answers:

5

I need to count unique values in range (C2:C2080) in excel. Googled formula:

=SUM(IF(FREQUENCY(MATCH(C2:C2080;C2:C2080;0);MATCH(C2:C280;C2:C2080;0))>0;1))

return incorrect value.

UPD: Lame solution:

Sub CountUnique()

Dim i, count, j As Integer

count = 1
For i = 1 To 470
    flag = False
    If count > 1 Then
        For j = 1 To count
            If Sheet1.Cells(i, 3).Value = Sheet1.Cells(j, 11).Value Then
                flag = True
            End If
        Next j
    Else
        flag = False
    End If

    If flag = False Then
        Sheet1.Cells(count, 11).Value = Sheet1.Cells(i, 3).Value
        count = count + 1
    End If

Next i

Sheet1.Cells(1, 15).Value = count

End Sub
A: 

The formula works for me. There are a few things that could cause this to not work. First, all target cells must have a value in them. Another example of where this might not work is if you have one cell with the value 31 and another cell with a text value of "31". It will recognize these as different values.

You could try this:

=SUM(IF(FREQUENCY(IF(LEN(B2:B11)>0,MATCH(B2:B11,B2:B11,0),""), IF(LEN(B2:B11)>0,MATCH(B2:B11,B2:B11,0),""))>0,1))

This is an array formula. Instead of hitting just enter to confirm it you must hit ctrl+shift+enter.

Which is from:

http://www.cpearson.com/excel/Duplicates.aspx

Dan
+3  A: 

Try:

=SUM(IF(FREQUENCY(C2:C2080,C2:C2080)>0,1))

EDIT: The above will handle blank entries in the column

Jacob
+2  A: 
not working for me, but i've managed to make a good one out of yours. thanx.
dayan
A: 

this link has various options that allow for text/numbers/both http://www.get-digital-help.com/2009/10/29/count-unique-text-values-in-a-range-containing-both-numerical-and-text-values/

guitarthrower
A: 

You could also simply use a filter to temporarily display unique values, and count the filtered values.

Mathias