VBA to find a text match that is closest & return value

harts

Board Regular
Joined
Apr 5, 2011
Messages
111
Office Version
  1. 365
Platform
  1. Windows
Both of these work finding the information I need except here is the part I have issues with, the name in row1 and the name in column BP are not an exact match. The names in BP are mostly partials. It would work if I could find just the first part of the name instead of the entire thing. Thanks in advance for any help.

Sub test2()
With Range("D4:AZ4")
.Formula = "=ifna(index($BS1:$BS40,match(D1,$BP1:$BP40,0)),"""")"
.Value = .Value
End With
End Sub

or

Sub test()
Darray = Range("D1:az4")
Bfarray = Range("BP1:BS40")
For i = 1 To UBound(Darray, 2)
For j = 1 To UBound(Bfarray, 1)
If Darray(1, i) = Bfarray(j, 1) Then
Darray(4, i) = Bfarray(j, 4)
Exit For
End If
Next j
Next i
Range("D1:az4") = Darray

End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
With no idea what the values look like it's impossible to provide a focused answer. Did you look at any of the string functions to compare values?
Perhaps Left, Right, Mid, Instr, InstrRev or a combination of those might work.

If you need to get really complicated, you can find code that works on the principle of Levenshtein Distance.
 
Upvote 0

Forum statistics

Threads
1,215,078
Messages
6,122,997
Members
449,093
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top