Sub Compare()
Dim t, d As Object, tablo, resu(), i&, x$, j%, y$, lig&, car$, k%, c$
t = Timer
Set d = CreateObject("Scripting.Dictionary")
With [A1].CurrentRegion
tablo = .Resize(, 2) 'matrice plus rapide, au moins 2 éléments
ReDim resu(1 To UBound(tablo), 1 To 2)
'---liste des textes sans doublon---
For i = 2 To UBound(tablo)
x = LCase(tablo(i, 1))
If Not d.exists(x) Then d(x) = i 'mémorise la ligne
Next i
'---recherche des textes réduits ou remplacés---
For i = 2 To UBound(tablo)
x = LCase(tablo(i, 1))
For j = 1 To Len(x)
y = Left(x, j - 1) & Mid(x, j + 1) 'texte réduit de 1 caractère
If d.exists(y) Then
lig = d(y)
If InStr(", " & resu(i, 1) & ", ", ", " & lig & ", ") = 0 Then 'évite les doublons
If resu(i, 1) = "" Then resu(i, 1) = lig Else resu(i, 1) = resu(i, 1) & ", " & lig
If resu(i, 2) = "" Then resu(i, 2) = tablo(lig, 1) Else resu(i, 2) = resu(i, 2) & ", " & tablo(lig, 1)
End If
If InStr(", " & resu(lig, 1) & ", ", ", " & i & ", ") = 0 Then 'évite les doublons
If resu(lig, 1) = "" Then resu(lig, 1) = i Else resu(lig, 1) = resu(lig, 1) & ", " & i
If resu(lig, 2) = "" Then resu(lig, 2) = tablo(i, 1) Else resu(lig, 2) = resu(lig, 2) & ", " & tablo(i, 1)
End If
End If
Next j
For j = 1 To Len(x)
car = LCase(Mid(x, j, 1))
For k = 32 To 255
c = LCase(Chr(k))
If c <> car And k <> 178 And k <> 179 And k <> 185 Then
y = Left(x, j - 1) & c & Mid(x, j + 1) 'texte avec 1 caractère remplacé
If d.exists(y) Then
lig = d(y)
If InStr(", " & resu(i, 1) & ", ", ", " & lig & ", ") = 0 Then 'évite les doublons
If resu(i, 1) = "" Then resu(i, 1) = lig Else resu(i, 1) = resu(i, 1) & ", " & lig
If resu(i, 2) = "" Then resu(i, 2) = tablo(lig, 1) Else resu(i, 2) = resu(i, 2) & ", " & tablo(lig, 1)
End If
If InStr(", " & resu(lig, 1) & ", ", ", " & i & ", ") = 0 Then 'évite les doublons
If resu(lig, 1) = "" Then resu(lig, 1) = i Else resu(lig, 1) = resu(lig, 1) & ", " & i
If resu(lig, 2) = "" Then resu(lig, 2) = tablo(i, 1) Else resu(lig, 2) = resu(lig, 2) & ", " & tablo(i, 1)
End If
End If
End If
Next k, j, i
'---restitution---
.AutoFilter: .AutoFilter 'si le tableau est filtré
resu(1, 1) = "Lignes similaires"
resu(1, 2) = "Textes similaires"
.Columns(2).Resize(, 2) = resu
End With
Columns.AutoFit 'ajustement largeurs
MsgBox "Durée des calculs " & Format(Timer - t, "0.00")
End Sub