Boinjour à tous,
Pour visualiser les correspondances, essaie ceci :
le regex reste perfectible
Le contenu de tes cellules est tronqué, revoie la hauteur de tes lignes
Option Explicit
Sub test()
Dim r As Range, rng As Range, myPtn As String, m As Object
With Sheets("prenoms")
myPtn = Join$(Application.Transpose(.Range("a2", .Range("a" & Rows.Count).End(xlUp)).Value), "|")
'myPtn = Join$(Application.Transpose(.Range("a2", .Range("a2").End(xlDown)).Value), "|")
End With
With Sheets("Sources")
Set rng = .Range("c2", .Range("c" & .Rows.Count).End(xlUp))
End With
With CreateObject("VBScript.RegExp")
.Global = True
.IgnoreCase = True
.Pattern = "\b(" & myPtn & ")\b"
For Each r In rng
For Each m In .Execute(r.Value)
r.Characters(m.firstindex + 1, m.Length).Font.Color = vbRed
Next
Next
End With
End Sub
ou cela :
Sub test1()
Dim r As Range, rng As Range, myPtn As String, m As Object
With Sheets("prenoms")
'myPtn = = Join$(Application.Transpose(.Range("a2", .Range("a" & Rows.Count).End(xlUp)).Value), "|")
myPtn = Join$(Application.Transpose(.Range("a2", .Range("a2").End(xlDown)).Value), "|")
End With
With Sheets("Sources")
Set rng = .Range("c2", .Range("c" & .Rows.Count).End(xlUp))
End With
With CreateObject("VBScript.RegExp")
.Global = True
.IgnoreCase = True
.Pattern = "\b(" & myPtn & ")\b"
For Each r In rng
For Each m In .Execute(r.Value)
r(, 2).Value = r(, 2).Value & Chr(32) & m.Value
Next
Next
End With
End Sub
As-tu pris en compte les remarques d'eriiic ?
klin89