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
-
WU help needed with “Some settings are managed by your organization”
by
Peobody
5 hours, 44 minutes ago -
No Newsletters since 27 January
by
rog7
1 hour, 41 minutes ago -
Linux Mint Debian Edition 7 gets OEM support, death of Ubuntu-based Mint ?
by
Alex5723
10 hours, 14 minutes ago -
Windows Update “Areca Technology Corporation – System – 6.20.0.41”
by
Bruce
51 minutes ago -
Google One Storage Questions
by
LHiggins
12 hours, 34 minutes ago -
Button Missing for Automatic Apps Updates
by
pmcjr6142
7 hours, 50 minutes ago -
Ancient SSD thinks it’s new
by
WSila
4 hours, 49 minutes ago -
Washington State lab testing provider exposed health data of 1.6 million people
by
Nibbled To Death By Ducks
20 hours, 33 minutes ago -
WinRE KB5057589 fake out
by
Susan Bradley
13 hours, 52 minutes ago -
The April 2025 Windows RE update might show as unsuccessful in Windows Update
by
Susan Bradley
4 hours, 30 minutes ago -
Firefox 137
by
Charlie
50 minutes ago -
Whisky, a popular Wine frontend for Mac gamers, is no more
by
Alex5723
1 day, 8 hours ago -
Windows 11 Insider Preview build 26120.3863 (24H2) released to BETA
by
joep517
1 day, 9 hours ago -
Windows 11 Insider Preview build 26200.5551 released to DEV
by
joep517
1 day, 9 hours ago -
New Windows 11 PC setup — can I start over in the middle to set up a local id?
by
ctRanger
4 hours, 59 minutes ago -
Windows 11 Insider Preview Build 26100.3902 (24H2) released to Release Preview
by
joep517
1 day, 12 hours ago -
Oracle kinda-sorta tells customers it was pwned
by
Nibbled To Death By Ducks
1 day, 18 hours ago -
Global data centers (AI) are driving a big increase in electricity demand
by
Kathy Stevens
2 days, 5 hours ago -
Office apps read-only for family members
by
b
2 days, 7 hours ago -
Defunct domain for Microsoft account
by
CWBillow
2 days, 4 hours ago -
24H2??
by
CWBillow
4 hours, 53 minutes ago -
W11 23H2 April Updates threw ‘class not registered’
by
WindowsPersister
46 minutes ago -
Master patch listing for April 8th, 2025
by
Susan Bradley
4 hours, 43 minutes ago -
TotalAV safety warning popup
by
Theodore Nicholson
1 day, 3 hours ago -
two pages side by side land scape
by
marc
4 days, 5 hours ago -
Deleting obsolete OneNote notebooks
by
afillat
4 days, 7 hours ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
3 days, 10 hours ago -
Security Essentials or Defender?
by
MalcolmP
3 days, 13 hours ago -
April 2025 updates out
by
Susan Bradley
47 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
3 days, 6 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.