Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Imperfect Matches

My Spreadsheet has one column with a list of Customer NameCodes.
Another column will be filled with comments that include portions of the
NameCodes or the NameCodes plus more characters.

Is there a way to have the macro identify close matches?

Simplified Sample:

A B
JohnD Sold 100 widgets to JohnDoe
Mary Smith Sold John D 100 large widgets
BenH Received from Mary 6 return items

--
Best wishes,

Jim
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Imperfect Matches

Sub FindMatches()
Dim rng As Range, rng1 As Range
Dim cell As Range, cell1 As Range
Dim bFound As Boolean, v As Variant
Set rng = Range(Cells(1, 2), Cells(1, 2).End(xlDown))
Set rng1 = Range(Cells(1, 1), Cells(1, 1).End(xlDown))
For Each cell In rng
For Each cell1 In rng1
bFound = False
If InStr(1, Replace(cell, " ", ""), Replace(cell1, " ", ""),
vbTextCompare) 0 Then _
bFound = True
If Not bFound Then
v = Split(cell1, " ")
For i = LBound(v) To UBound(v)
If InStr(1, Replace(cell, " ", ""), v(i), vbTextCompare) 0
Then
bFound = True
Exit For
End If
Next i
End If
If bFound Then
cell.Offset(0, 1).Value = cell1
End If
Next
Next
End Sub

as a start.

Against your data it returned

JohnD
JohnD
Mary Smith

--
Regards,
Tom Ogilvy


"Jim Jackson" wrote:

My Spreadsheet has one column with a list of Customer NameCodes.
Another column will be filled with comments that include portions of the
NameCodes or the NameCodes plus more characters.

Is there a way to have the macro identify close matches?

Simplified Sample:

A B
JohnD Sold 100 widgets to JohnDoe
Mary Smith Sold John D 100 large widgets
BenH Received from Mary 6 return items

--
Best wishes,

Jim

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Imperfect Matches

Thanks, Tom.

I am getting some "false positives" but should be able to iron those out
with some experimentation.
--
Best wishes,

Jim


"Tom Ogilvy" wrote:

Sub FindMatches()
Dim rng As Range, rng1 As Range
Dim cell As Range, cell1 As Range
Dim bFound As Boolean, v As Variant
Set rng = Range(Cells(1, 2), Cells(1, 2).End(xlDown))
Set rng1 = Range(Cells(1, 1), Cells(1, 1).End(xlDown))
For Each cell In rng
For Each cell1 In rng1
bFound = False
If InStr(1, Replace(cell, " ", ""), Replace(cell1, " ", ""),
vbTextCompare) 0 Then _
bFound = True
If Not bFound Then
v = Split(cell1, " ")
For i = LBound(v) To UBound(v)
If InStr(1, Replace(cell, " ", ""), v(i), vbTextCompare) 0
Then
bFound = True
Exit For
End If
Next i
End If
If bFound Then
cell.Offset(0, 1).Value = cell1
End If
Next
Next
End Sub

as a start.

Against your data it returned

JohnD
JohnD
Mary Smith

--
Regards,
Tom Ogilvy


"Jim Jackson" wrote:

My Spreadsheet has one column with a list of Customer NameCodes.
Another column will be filled with comments that include portions of the
NameCodes or the NameCodes plus more characters.

Is there a way to have the macro identify close matches?

Simplified Sample:

A B
JohnD Sold 100 widgets to JohnDoe
Mary Smith Sold John D 100 large widgets
BenH Received from Mary 6 return items

--
Best wishes,

Jim

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
matches LBTeacher Excel Discussion (Misc queries) 3 November 12th 05 03:51 AM
Multibul matches Mrbanner Excel Discussion (Misc queries) 0 July 29th 05 05:46 AM
matches Ray Newman via OfficeKB.com Excel Discussion (Misc queries) 3 February 7th 05 11:09 PM
Searching for matches pkohler[_2_] Excel Programming 3 May 10th 04 07:39 PM
Looking for matches Bill C[_4_] Excel Programming 2 April 13th 04 05:43 PM


All times are GMT +1. The time now is 03:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"