Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. Public FirstInstance As Long, Dup As Boolean
  2.  
  3. Sub HighlightDups()
  4. Dim MyDictionary As Scripting.Dictionary
  5. Set MyDictionary = New Scripting.Dictionary
  6. Dim MyDictionaryEntry As DictionaryEntry
  7. Dim MyColour, palette, contents As Integer
  8. Dim i, LastRow As Long
  9. palette = 2
  10.  
  11. With ActiveSheet
  12. LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
  13. End With
  14.  
  15.  
  16. With MyDictionary
  17. For i = 1 To LastRow
  18. Debug.Print (i)
  19. contents = Cells(i, 1)
  20. Debug.Print (contents)
  21.  
  22. ' New key - create entry
  23. If Not .Exists(contents) Then
  24. Debug.Print ("Not exists")
  25. Set MyDictionaryEntry = New DictionaryEntry
  26. MyDictionaryEntry.FirstInstance = i
  27. .Add contents, MyDictionaryEntry
  28. Else
  29.  
  30. 'Dup already found - retrieve previous colour
  31. If .Item(contents).Dup Then
  32. MyColour = Cells(.Item(contents).FirstInstance, 1).Interior.ColorIndex
  33. Cells(i, 1).Interior.ColorIndex = MyColour
  34.  
  35. ' Dup not previously found - set new colour
  36. Else
  37. palette = palette + 1
  38. .Item(contents).Dup = True
  39. Cells(i, 1).Interior.ColorIndex = palette
  40. Cells(.Item(contents).FirstInstance, 1).Interior.ColorIndex = palette
  41. End If
  42. End If
  43. Next i
  44. End With
  45.  
  46. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement