1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Option Explicit
Sub Macro222()
Call HighlightWord(Range("F1"), Range("A1:A30"))
End Sub
Sub HighlightWord(ByVal str As String, r As Range)
Dim res As Range
Dim firstAddress As String, pos As Long
' on fait une recherche sur la plage
With r.Cells
Set res = .Find(What:=str, After:=r.Cells(1, 1), LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not res Is Nothing Then
firstAddress = res.Address
Do
pos = InStr(res.Value, str)
Do While pos > 0
With res.Characters(pos, Len(str))
'ici on mettra en gras rouge
.Font.Color = vbRed
.Font.Bold = True
End With
pos = InStr(pos + 1, res.Value, str)
Loop
Set res = .Find(What:=str, After:=res, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Loop While Not res Is Nothing And res.Address <> firstAddress
End If
End With
Set res = Nothing
End Sub |
Partager