D'accord, j'ai essayé de find une solution pour cela et je ne semble pas pouvoir. Je ne peux même pas décomposer le problème correctement. C'est l'idée.
J'ai deux feuilles avec plusieurs lignes (une avec 800 et l'autre avec 300 000). Chaque ligne contient une colonne Nom puis plusieurs colonnes contenant des informations sur ce Nom. Chaque feuille possède différents types d'informations.
Je veux consolider ces deux feuilles dans une feuille maîtresse basée sur cette colonne Nom qu'ils ont toutes deux, de sorte que la fonction de consolidation est parfaite pour cela. Maintenant, le problème est que les noms ne correspondent pas parfaitement.
Par exemple, Sheet1 contient
"Société BV", "Info # 1"
"Compagnie totale", "Info # 2"
"Company Ltd", "Info # 3"
et la feuille 2 contient
"Société et société", "Info # 4"
"Société et Co", "Info # 5"
La feuille 1 contient tous les noms qui vont être utilisés (autour d'un 100 mais sous différentes forms comme indiqué ci-dessus) et la feuille 2 contient tous ces 100 dans plusieurs lignes plus des noms qui ne figurent pas dans la list 100 et donc je ne le fais pas s'en soucient.
Comment ferais-je un projet de code VBA où le résultat final serait quelque chose comme ça, feuille maître:
"Société", "Info # 1", "Info # 2", "Info # 3", "Info # 4", "Info # 5"
pour chaque «société» (la list 100) là-bas?
J'espère qu'il y a une solution à cela. Je suis assez nouveau pour les projets VBA, mais j'ai déjà fait un petit encoding.
Je placerais la macro dans ta section PERSONNELLE, de sorte que la macro est disponible dans toutes les feuilles de calcul. Effectuez ceci en enregistrant une macro fictive et select pour le stocker dans le classur Personal Macro. Vous pouvez maintenant append manuellement de nouvelles macro et fonctions dans ce classur personnel.
Je viens d'essayer celui-ci (je ne connais pas la source d'origine) et ça marche bien.
La formule ressemble à ceci: = PERSONAL.XLSB! FuzzyFind (A1, B $ 1: B $ 20)
Le code est ici:
Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
Fonction FuzzyFind (lookup_value As Ssortingng, tbl_array As Range) As SsortingngFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
Dim i As Integer, str As Ssortingng, Value As SsortingngFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
Dim a As Integer, b Comme Integer, cell As VariantFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
Pour chaque cellule dans tbl_arrayFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
str = celluleFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
Pour i = 1 To Len (lookup_value)Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
Si InStr (cell, Mid (lookup_value, i, 1))> 0 ThenFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
a = a + 1Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
cell = Mid (cellule, 1, InStr (cell, Mid (lookup_value, i, 1)) - 1) & Mid (cell, InStr (cell, Mid (lookup_value, i, 1)) + 1, 9999)Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
a = a - Len (cellule)Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
Si a> b EnsuiteFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
b = aFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
Valeur = strFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
a = 0Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
Cellule suivanteFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
FuzzyFind = valeurFunction FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid(cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell FuzzyFind = Value End Function
J'ai utilisé la solution Robert et ça marche bien pour moi. Je publie une solution complète pour les personnes nouvelles pour Excel, mais connais le encoding:
Bien que ce thread soit ancien, mais j'ai pris un code à partir d'un autre thread et j'ai essayé et la solution est de donner une correspondance approximative. Ici, j'essaie de faire correspondre une colonne de feuille1 avec une colonne de feuille2:
Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Private Sub CommandButton21_Click ()Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Dim ws As WorksheetPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Dim LRow As Long, i As Long, lval As SsortingngPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
'~~> Modifiez ceci à la feuille de route pertinentePrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Définir ws = ThisWorkbook.Sheets ("Sheet1")Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Avec wsPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
'~~> Trouver la dernière rangée dans Col G qui a des donnéesPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
LRow = .Range ("D" et .Rows.Count) .End (xlUp) .RowPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Si LRow = 1 ThenPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
MsgBox "Aucune donnée dans la colonne D"Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Pour i = 2 à LRowPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
lval = "D"Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
.Range ("G" & i) .Value = FuzzyFind (lval & i, .Range ("PWC"))Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Fonction FuzzyFind (lookup_value As Ssortingng, tbl_array As Range) As SsortingngPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Dim i As Integer, str As Ssortingng, Value As SsortingngPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Dim a As Integer, b Comme Integer, cell As VariantPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Pour chaque cellule dans tbl_arrayPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
str = cellulePrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Pour i = 1 To Len (lookup_value)Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Si InStr (cell, Mid (lookup_value, i, 1))> 0 ThenPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
a = a + 1Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
cell = Mid (cellule, 1, InStr (cell, Mid (lookup_value, i, 1)) - 1) & Mid (cell, InStr (cell, Mid (lookup_value, i, 1)) + 1, 9999)Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
a = a - Len (cellule)Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Si a> b EnsuitePrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
b = aPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Valeur = strPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
a = 0Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Cellule suivantePrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Si la valeur <> "" EnsuitePrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
FuzzyFind = valeurPrivate Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
FuzzyFind = "Aucun"Private Sub CommandButton21_Click() Dim ws As Worksheet Dim LRow As Long, i As Long, lval As Ssortingng '~~> Change this to the relevant worsheet Set ws = ThisWorkbook.Sheets("Sheet1") With ws '~~> Find Last Row in Col G which has data LRow = .Range("D" & .Rows.Count).End(xlUp).Row If LRow = 1 Then MsgBox "No data in column D" Else For i = 2 To LRow lval = "D" .Range("G" & i).Value = FuzzyFind(lval & i, .Range("PWC")) Next i End If End With End Sub Function FuzzyFind(lookup_value As Ssortingng, tbl_array As Range) As Ssortingng Dim i As Integer, str As Ssortingng, Value As Ssortingng Dim a As Integer, b As Integer, cell As Variant For Each cell In tbl_array str = cell For i = 1 To Len(lookup_value) If InStr(cell, Mid(lookup_value, i, 1)) > 0 Then a = a + 1 cell = Mid(cell, 1, InStr(cell, Mid(lookup_value, i, 1)) - 1) & Mid (cell, InStr(cell, Mid(lookup_value, i, 1)) + 1, 9999) End If Next i a = a - Len(cell) If a > b Then b = a Value = str End If a = 0 Next cell If Value <> "" Then FuzzyFind = Value Else FuzzyFind = "None" End If End Function
Vous pouvez searchr Google Excel UDF Fuzzy ou à distance Levensthein. Il y a des UDF flottant autour et Microsoft a également un add-on Fuzzy Lookup / match (quand je l'ai utilisé, il était sujet à une panne et pas intuitif).
Regardez les fonctions de cette publication DDoE . Vous pouvez générer une string de séquence commune la plus longue et comparer la longueur à la string d'origine. Alimentez-en des allumettes connues et des matchs non correspondants et vérifiez si vous pouvez voir une ligne de séparation claire entre eux.
Ces fonctions sont utilisées pour diffuser, ne pas find des correspondances proches, mais elles peuvent fonctionner pour vous.