Count unique values in Excel

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

    For anyone still trying to use @JustinG's dictionary method, you will need to alter the code slightly if you're using a newer version of VBA.

    You'll need to reference 'Microsoft Scripting Runtime' and prefix the Dictionary terms with Scripting, as follows:

    Public Function CountUnique(rng As Range) As Long
        Dim dict As Scripting.Dictionary
        Dim cell As Range
        Set dict = New Scripting.Dictionary
        For Each cell In rng.Cells
             If Not dict.Exists(cell.Value) Then
                dict.Add cell.Value, 0
            End If
        Next
        CountUnique = dict.Count
    End Function
    

提交回复
热议问题