MS Excel - count partial matches between two columns

I am attempting to write a formula that will count partial matches between two different ranges.

Column 1 Range:  A1:A4
A1 - A123456789
A2 -  A6789
A3 - 12345
A4 - 11111

Column 2 Range:  B1:B4
B1 - 12345
B2 - 6789
B3 - 11111
B4 - B12345

Basically, I am trying to develop formulas that i can display a count indicating:

The number of times the first 4 characters match
The number of times the last 4 characters match
The number of times the middle 4 characters match

*Note:  There are not duplicates within each range.  

Any suggestions would be greatly appreciated. Thank you in advance for reviewing my question.
LenCepedaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rob HensonFinance AnalystCommented:
Can you clarify what would be a match?

the first four characters from A match the first 4 characters from B
the first four characters from B match the first 4 characters from A
the first four characters from A are found within B
the first four characters from B are found within A

Thanks
Rob H
LenCepedaAuthor Commented:
Hi Rob,

Thanks for getting back to quickly

The first four characters from A are found within B
The last four characters from A are found within B
Rob HensonFinance AnalystCommented:
Sorry, should have also asked, in the same row or anywhere within the range?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

LenCepedaAuthor Commented:
Anywhere within the range.
Martin LissOlder than dirtCommented:
Insert a module if you don't already have one and add this User Defined Function.

Usage:
=F4L4(A1,B$1:B$4)

That formula could be placed in C1 and copied down to C4

Function F4L4(A As Range, B As Range) As Integer
' Counts the occurrences whwre the first four characters from A are found within B
' and/or the last four characters from A are found within B
Dim lngRow As Long

For lngRow = 1 To B.Rows.Count
    If InStr(1, Cells(lngRow, B.Column), Left$(A, 4)) > 0 Then
        F4L4 = F4L4 + 1
    End If
    If InStr(1, Cells(lngRow, B.Column), Right$(A, 4)) > 0 Then
        F4L4 = F4L4 + 1
    End If
Next
End Function

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LenCepedaAuthor Commented:
Wow, thank you very much.

I have a lunch appointment now but will test it out as soon as return to the office .  Thanks again.
LenCepedaAuthor Commented:
I can't thank you enough - this worked out great.

I modified the range to suit the appropriate number of rows and even increased the number of characters from 4 to 6 as I quickly realized I underestimated the similarities between the two columns.  

Your efforts are very much appreciated.  

Thank you and regards.
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.