Option Explicit
Sub ApplyColorDouble()
Dim p As Range, I&, Dico As Object, X&: X = 1
Set Dico = CreateObject("scripting.dictionary")
Set p = Feuil1.Range("B1", Cells(Rows.Count, "B").End(xlUp))
p.Interior.Color = xlNone
p.Font.Color = 0
For I = 1 To p.Cells.Count
If Application.CountIf(p, Trim(p.Cells(I).Text)) > 1 Then
If Not Dico.exists(Trim(p.Cells(I).Text)) Then
X = X + 1: If X = 2 Then X = 3:
Dico(Trim(p.Cells(I).Value)) = X
p.Cells(I).Interior.ColorIndex = X
Else
p.Cells(I).Interior.ColorIndex = Val(Dico(Trim(p.Cells(I).Text)))
End If
End If
'visibilité du font en cas de couleur trop foncée on met le font en blanc
Select Case p.Cells(I).Interior.ColorIndex
Case 1, 3, 5, 7, 9, 10, 11, 13, 14, 18, 21, 23, 25, 29, 30, 31, 32, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56: p.Cells(I).Font.ColorIndex = 2
End Select
Next
End Sub