I have 2 sources of data that I am trying to match. One is from an Access database, the other from an interface to a company system. Both contain unique case ID fields. The fields could be returned in formats that are not exactly the same. E.g. db= 0123408AUG03 sys= 1234-08AUG03. I am creating a sheet that will list everything from the sys, while returning specific information from the database if the IDs match up. The problem is that the formulas I am trying to use rely on an exact, less than, or more than match. I’ve already written some formulas that remove leading zeros and eliminate the dash, if there is one. I now want the evaluation to do something like this: If there are at least 6 consecutive characters that match, return the specified information from the database. I want to use a formula like this because even with the elimination of the leading zeros and the dashs, I still don’t get exact matches using the INDEX and MATCH formulas. Got any ideas?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Match limited # characters in cell not exact (Excel 97)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Match limited # characters in cell not exact (Excel 97)
- This topic has 2 replies, 3 voices, and was last updated 17 years, 10 months ago.
AuthorTopicWScchambers@work
AskWoody LoungerAugust 8, 2003 at 5:36 pm #391743Viewing 0 reply threadsAuthorReplies-
WSsdckapr
AskWoody LoungerAugust 8, 2003 at 6:34 pm #700876Not sure if this is what you are looking for. I can see a lot of problems with finding the WRONG item. This code works like match. it takes the form (for example):
=nearmatch(A1,B1:B10,6)
A1 is the value to lookup
b1:b10 is the range
6 is the number of characters to “near match”
It starts with the value in A1 and takes the first 6 characters and looks through each item in the list. If it finds one, it exits giving the row number of the “near match”. If it doesn’t find any it gets the 2-7 characters and looks in each value in col B, then tries with 3-8, etc until the does the “last-6” – last character. if it finds none it gives a #N/A error.Option Explicit Function NearMatch(vLookupValue, rng As Range, iNumChars) Dim x As Integer Dim sSub As String Set rng = rng.Columns(1) For x = 1 To Len(vLookupValue) - iNumChars + 1 sSub = Mid(vLookupValue, x, iNumChars) For NearMatch = 1 To rng.Cells.Count If InStr(rng.Cells(NearMatch), sSub) 0 Then _ Exit Function Next Next NearMatch = CVErr(xlErrNA) End Function
This second one, takes the same form
=nearmatch2(A1,B1:B10,6)
A1 is the value to lookup
b1:b10 is the range
6 is the MINIMUM number of characters to “near match”
This starts out checking the entire string (like the MATCH functionality), if it does NOT find an exact match, it takes all but the last character and tries to find a match, it then tries all but the first character, then all but last 2 then, al but 1st and last, then all but first 2, then the missing 3 char variants, then 4 until it gets to the MINIMUM number of characters. If all fail #N/A. It quits once it finds a “near match”option explicit Function NearMatch2(vLookupValue, rng As Range, iMinChars) Dim x As Integer Dim i As Integer Dim sSub As String Set rng = rng.Columns(1) For i = Len(vLookupValue) To iMinChars Step -1 For x = 1 To Len(vLookupValue) - i + 1 sSub = Mid(vLookupValue, x, i) For NearMatch2 = 1 To rng.Cells.Count If InStr(rng.Cells(NearMatch2), sSub) 0 Then _ Exit Function Next Next Next NearMatch2 = CVErr(xlErrNA) End Function
This second will find the substring match with the MAX of characters, the first will ONLY use the value you gave it.
The “near match item” can be obtained easily using index:
=index(B1:b10,nearmatch2(A1,B1:B10,6))
so you can compare / “see” if the match is acceptable.
Steve
-
WSbraddy60
AskWoody Lounger
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
4 hours, 3 minutes ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
5 hours, 31 minutes ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
11 hours, 55 minutes ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
14 hours, 21 minutes ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
34 minutes ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
1 day, 16 hours ago -
50 years and counting
by
Susan Bradley
4 hours, 7 minutes ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
22 hours, 59 minutes ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
2 days, 3 hours ago -
Edge : Deprecating window.external.getHostEnvironmentValue()
by
Alex5723
2 days, 3 hours ago -
Rethinking Extension Data Consent: Clarity, Consistency, and Control
by
Alex5723
2 days, 3 hours ago -
OneNote and MS Word 365
by
CWBillow
2 days, 5 hours ago -
Ultimate Mac Buyers Guide 2025: Which Mac is Right For You?
by
Alex5723
2 days, 5 hours ago -
Intel Unison support ends on Windows 11 in June
by
Alex5723
2 days, 5 hours ago -
April 2025 — still issues with AMD + 24H2
by
Kevin Jones
26 minutes ago -
Windows 11 Insider Preview build 26200.5518 released to DEV
by
joep517
2 days, 17 hours ago -
Windows 11 Insider Preview build 26120.3671 (24H2) released to BETA
by
joep517
2 days, 17 hours ago -
Forcing(or trying to) save Local Documents to OneDrive
by
PateWilliam
3 days, 2 hours ago -
Hotpatch for Windows client now available (Enterprise)
by
Alex5723
2 days, 14 hours ago -
MS-DEFCON 2: Seven months and counting
by
Susan Bradley
1 day, 15 hours ago -
My 3 monitors go black & then the Taskbar is moved to center monitor
by
saturn2233
3 days, 11 hours ago -
Apple backports fixes
by
Susan Bradley
2 days, 17 hours ago -
Win 11 24H2 will not install
by
Michael1950
1 day, 15 hours ago -
Advice to convert MBR to GPT and install Windows 11 Pro on unsupported PC
by
Andy M
9 hours, 8 minutes ago -
Photos from iPhone to Win 10 duplicating/reformatting to .mov
by
J9438
1 day, 23 hours ago -
Thunderbird in trouble. Here comes Thundermail
by
Alex5723
11 hours, 37 minutes ago -
Get back ” Open With” in context menus
by
CWBillow
4 days, 2 hours ago -
Many AMD Ryzen 9800X3D on ASRock have died
by
Alex5723
2 days, 18 hours ago -
simple general stupid question
by
WSaltamirano
3 days, 23 hours ago -
April 2025 Office non-Security updates
by
PKCano
4 days, 16 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.