Finding Best Match [search for a match in a part of a cell]

BM604

New Member
Joined
Oct 30, 2014
Messages
15
Hi All,

Lets imagine I have two Columns A,B.

A
Bob
Elephant
Brokenwood
Laser

B
Az. Elephant Co
Bob's Market Ltd.
Brokenwood Ultimate Patio
Laserjet Enterprises

Column A has a partial match of a complete cell in column B. How can I use Column A and lookup Column B to pull the best most accurate match.

I.e. Bob would select Bob's Market because it is the best match.

Any help is greatly appreciated. Have a great weekend. Thank you.

<tbody>
</tbody>
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Not sure about "best" match, but this will find the first partial match in the complete list.
Excel Workbook
ABC
1PartialsCompleteBest Match
2BobAz. Elephant CoBob's Market Ltd.
3ElephantBob's Market Ltd.Az. Elephant Co
4BrokenwoodBrokenwood Ultimate PatioBrokenwood Ultimate Patio
5LaserLaserjet EnterprisesLaserjet Enterprises
Sheet5
 
Upvote 0
BM604,

You did not say how to display a match?

Here is a macro solution for you to consider that will adjust to the number of raw data rows.

Sample raw data in the active worksheet:


Excel 2007
ABC
1WordCompany
2BobAz. Elephant Co
3ElephantBob's Market Ltd.
4BrokenwoodBrokenwood Ultimate Patio
5LaserLaserjet Enterprises
6
Sheet1


After the macro:


Excel 2007
ABC
1WordCompanybest match for Word
2BobAz. Elephant CoBob's Market Ltd.
3ElephantBob's Market Ltd.Az. Elephant Co
4BrokenwoodBrokenwood Ultimate PatioBrokenwood Ultimate Patio
5LaserLaserjet EnterprisesLaserjet Enterprises
6
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub FindBestMatch()
' hiker95, 03/13/2015, ME842256
Dim c As Range, b As Range
With ActiveSheet
  .Columns(3).ClearContents
  With .Cells(1, 3)
    .Value = "best match for Word"
    .HorizontalAlignment = xlCenter
  End With
  For Each c In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    Set b = .Columns(2).Find("*" & c & "*", LookAt:=xlWhole)
    If Not b Is Nothing Then
      c.Offset(, 2).Value = .Cells(b.Row, 2).Value
    End If
  Next c
  .Columns(3).AutoFit
End With
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the FindBestMatch macro.
 
Upvote 0

Forum statistics

Threads
1,215,950
Messages
6,127,906
Members
449,411
Latest member
AppellatePerson

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