Closest Match in a Range

Bossi

New Member
Joined
Dec 28, 2010
Messages
10
Office Version
  1. 365
Platform
  1. Windows
With a given cell, I'm trying to figure out how to identify the nearest match from within a range.

Using license tags & partial tags as an example in the image below... let's say I have a list of tags in Column A. Where I only have a partial tag, I use a lower-case "x" to denote an unknown digit.

What I want Column B to do is, if there are any unknown (x) digits, to scan all of Column A for the nearest match tag to the input for that row. So for the first partial tag (Row 5), cell B5 would look for the closest match to A5 in all of A:A.

Then Column C would give the % match. So C5 would go "it matches 7 out of 9 total digits", or 78%.

---
In Row 8 is an example where the input only has 7 digits, whereas everything else has 9. My preference is that this would return 0%, as there are no other 7-digit matches. But if the only way to get everything else to work is to treat this as if it's a 9-digit input with additional two unknown digits... I could probably work with that.

---
(Hopefully I didn't make any mistakes in the example. And I rather suspect there are lingering "But what about this scenario?" questions I'm not yet thinking of)

1729021418154.png
 

Attachments

  • 1729021116644.png
    1729021116644.png
    27.5 KB · Views: 9

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
There are a couple of ideas:
- for the lookup/match you can use the Fuzzy Lookup add-in: Download Fuzzy Lookup Add-In for Excel from Official Microsoft Download Center
- the match of two strings: How compare two strings and count the number of matched characters? -> this has two formulas that can do the job and count the number of matching characters. Another option is to go for "Levenshtein distance", which accounts a bit better for missing characters etc.

If you want all your business rules (like the NJ vs PA result), you probably have to write some VBA code to get that in.
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,154
Members
452,615
Latest member
bogeys2birdies

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