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