title: Count unique values in Excel
body: <p>I need to count unique values in range (C2:C2080) in excel. Googled formula:</p>
  
  <pre><code>=SUM(IF(FREQUENCY(MATCH(C2:C2080;C2:C2080;0);MATCH(C2:C280;C2:C2080;0))&gt;0;1)) 
  </code></pre>
  
  <p>return incorrect value.</p>
  
  <p>UPD: Lame solution: </p>
  
  <pre><code>Sub CountUnique()
  
  Dim i, count, j As Integer
  
  count = 1
  For i = 1 To 470
      flag = False
      If count &gt; 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
  </code></pre>