1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Sub Colorer_mot_recherché()
Dim b As String, r As Range, s As String, f As String
b = Range("j2")
Set r = Cells.Find(b, lookat:=xlPart)
'lookat:=xlPart indique que la valeur trouvée peut être en partie égale à la valeur cherchée
If Not r Is Nothing Then
f = r.Address
Do
s = InStr(1, r.Value, b, vbTextCompare)
'vbTextCompare permet à la recherche de ne pas être sensible aux Maj/Minuscules
While s > 0
r.Characters(Start:=s, Length:=Len(b)).Font.Color = vbRed
'colore en rouge le/les mot(s) recherché(s)
s = InStr(s + 1, r.Value, b)
Wend
Set r = Cells.FindNext(r)
Loop Until r Is Nothing Or r.Address = f
End If
End Sub |
Partager