Count unique values in Excel

前端 未结 12 2235
别那么骄傲
别那么骄傲 2020-11-28 12:28

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))         


        
12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 12:41

    
    =SUM(IF(FREQUENCY(IF(LEN(A2:A10)>0,MATCH(A2:A10,A2:A10,0),""), IF(LEN(A2:A10)>0,MATCH(A2:A10,A2:A10,0),""))>0,1)) 
    

    http://office.microsoft.com/en-us/excel/HP030561181033.aspx

    You may also write a VBA macro (not sure if that's what you're after though.)

    Something to the effect of (given a spreadsheet with A1-A11 filled and B1-B11 empty):

    Sub CountUnique()
    
    Dim count As Integer
    Dim i, c, j As Integer
    
    c = 0
    count = 0
    For i = 1 To 11
        Sheet1.Cells(i, 2).Value = Sheet1.Cells(i, 1).Value
        c = c + 1
        For j = 1 To c
            If CDbl(Sheet1.Cells(i, 1).Value) = CDbl(Sheet1.Cells(j, 2).Value) Then
                c = c - 1
                Exit For
            End If
        Next j
    Next i
    
    ' c now equals the unique item count put in the 12'th row
    Sheet1.Cells(12, 1).Value = c
    
    End Sub
    

提交回复
热议问题