Sub test()
Dim a, i As Long, temp, rng As Range
Dim dic As Object, r As Long, g As Long, b As Long
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
With Range("A3", Range("A" & Rows.Count).End(xlUp))
a = .Value: Set rng = .Cells
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 1 To UBound(a, 1)
If a(i, 1) <> "" Then .Item(a(i, 1)) = .Item(a(i, 1)) + 1
Next i
For i = 1 To UBound(a, 1)
temp = a(i, 1)
If Not dic.exists(temp) Then
r = Application.RandBetween(0, 255)
g = Application.RandBetween(0, 255)
b = Application.RandBetween(0, 255)
dic(temp) = RGB(r, g, b)
End If
a(i, 1) = .Item(a(i, 1))
If a(i, 1) > 1 Then rng.Cells(i, 1).Interior.Color = dic(temp)
Next i
End With
.Columns("I").Value = a
End With
End Sub
Bookmarks