Option Compare Text 'la casse est ignorée
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cible$, L%, choix$, nlig&, a, i&, x$, j%, coloreMot As Boolean, test As Boolean
If Intersect(Target, [D2:E2]) Is Nothing Then Exit Sub
cible = CStr([D2])
If cible = "" Then cible = Chr(1)
L = Len(cible)
choix = [E2] 'liste de validation
Application.ScreenUpdating = False
Columns(1).Clear 'RAZ
With Feuil1.Range("B1", Feuil1.Range("B1048576").End(xlUp))
.AutoFilter
.AutoFilter 1, "*" & cible & "*"
.SpecialCells(xlCellTypeVisible).Copy [A1]
.AutoFilter
End With
nlig = [A1].CurrentRegion.Rows.Count
ReDim a(1 To nlig, 1 To 2)
a(1, 1) = "Nbre occurences": a(1, 2) = "Nbre mots"
For i = 2 To nlig
x = Cells(i, 1)
For j = 1 To Len(x) - L + 1
If Mid(x, j, L) = cible Then
a(i, 1) = a(i, 1) + 1: a(i, 2) = a(i, 2) + 1
coloreMot = choix = "Mots"
test = Mid(x, j + L, 1) Like "[A-Z]" Or Mid(x, j + L, 1) Like "[0-9]"
If j = 1 And test Then a(i, 2) = a(i, 2) - 1: coloreMot = False
If j > 1 Then If Mid(x, j - 1, 1) Like "[A-Z]" Or Mid(x, j - 1, 1) Like "[0-9]" Or test Then a(i, 2) = a(i, 2) - 1: coloreMot = False
If coloreMot Or choix = "Occurrences" Then Cells(i, 1).Characters(j, L).Font.Color = vbRed
End If
Next j, i
[B1].Resize(nlig, 2) = a
[B1].Offset(nlig).Resize(Rows.Count - nlig, 2).ClearContents 'RAZ en dessous
End Sub