Advertisement
illpastethat

Excel count unique values

Jul 29th, 2015
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Enable Microsoft scripting library first via Tools > References > Microsoft Scripting Library/Runtime
  2. Public Function CountUnique(rng As range) As Integer
  3.     Dim dict As Dictionary
  4.     Dim cell As range
  5.     Set dict = New Dictionary
  6.     For Each cell In rng.Cells
  7.          If Not dict.Exists(cell.Value) Then
  8.             dict.Add cell.Value, 0
  9.         End If
  10.     Next
  11.     CountUnique = dict.Count
  12. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement