See Attachment!! Create New NameManager of PWC of Range E:E This is UDF Formula J2 =FUZZYFIND(A2,PWC) fill down. for cost DO=VLOOKUP(J2,$E$2:$F$23,2,0)
Here
Private Sub CommandButton21_Click()
Dim ws As Worksheet
Dim LRow As Long, i As Long, lval As String
'~~> 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 String, tbl_array As Range) As String
Dim i As Integer, str As String, Value As String
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
Code credits to Robert solution
Bookmarks