Count unique values in Excel

前端 未结 12 2255
别那么骄傲
别那么骄傲 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:45

    Another way to do this is this:

    Sub CountUnique()
        Dim Count, x, a, lastRow, Values(), StringValues
        a = ActiveCell.Column
        a = GetLetterFromNumber(a)
        lastRow = Range(a & Rows.Count).End(xlUp).row
        Count = 0
        For Each c In Range(Range(a & "1"), Range(a & Rows.Count).End(xlUp))
            If c.row = 1 Then
                ReDim Values(lastRow)
                Values(Count) = c.Value
                Count = Count + 1
            End If
            StringValues = Join(Values, "#")
            StringValues = "#" + StringValues
            If InStr(1, StringValues, c.Value) = 0 Then
                Values(Count) = c.Value
                Count = Count + 1
            End If
        Next c
        MsgBox "There are " & Count & " unique values in column " & a
    End Sub
    

    You just have to have the active cell be on row 1 of the column that you are counting.

提交回复
热议问题