Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
LEsa
 
Posts: n/a
Default How to match two different cells text, if the text is not in the .

Column A has Bob Fred Tom
Column B has Tom Bob Fred

I would like to match and identify someway

Column A has Bobby Fred Tom
Column B has Fred Tom Bob
That is not a match

I use vlookup to get exact matches. How to get matches if word order is
different?
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

How about this.

Sort the data in each cell in each column. Then compare those sorted cells.

I'd insert two new columns that would hold that sorted string.
(say C and D)

then put a formula like:
=sortthecell(a1)
in C1 and drag down

=sortthecell(b1)
in D1 and drag down

But now you'll need something that will actually sort the contents of the cell.

Depending on your version of excel, you can use this:
(for xl2k or higher):

Option Explicit
Function SortTheCell(rng As Range) As String

Dim mySplit As Variant
Dim Temp As String
Dim iCtr As Long
Dim jCtr As Long
Dim myStr As String

Set rng = rng(1)
mySplit = Split(rng.Value, " ")

For iCtr = LBound(mySplit) To UBound(mySplit) - 1
For jCtr = iCtr + 1 To UBound(mySplit)
If LCase(mySplit(iCtr)) LCase(mySplit(jCtr)) Then
Temp = mySplit(iCtr)
mySplit(iCtr) = mySplit(jCtr)
mySplit(jCtr) = Temp
End If
Next jCtr
Next iCtr

SortTheCell = Join(mySplit, " ")

End Function

or both these (xl97):

Option Explicit
Function SortTheCell(rng As Range) As String

Dim mySplit As Variant
Dim Temp As String
Dim iCtr As Long
Dim jCtr As Long
Dim myStr As String

Set rng = rng(1)
mySplit = Split97(rng.Value, " ")

For iCtr = LBound(mySplit) To UBound(mySplit) - 1
For jCtr = iCtr + 1 To UBound(mySplit)
If LCase(mySplit(iCtr)) LCase(mySplit(jCtr)) Then
Temp = mySplit(iCtr)
mySplit(iCtr) = mySplit(jCtr)
mySplit(jCtr) = Temp
End If
Next jCtr
Next iCtr

myStr = ""
For iCtr = LBound(mySplit) To UBound(mySplit)
myStr = myStr & " " & mySplit(iCtr)
Next iCtr
SortTheCell = Mid(myStr, 2)

End Function
'from Tom Ogilvy
Function Split97(sStr As String, sdelim As String) As Variant
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function

==========
If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=sortthecell(a1)

========
After you have these two helper columns of sorted values, you can use some of
the techniques at Chip Pearson's to find your duplicates:

http://www.cpearson.com/excel/duplicat.htm

LEsa wrote:

Column A has Bob Fred Tom
Column B has Tom Bob Fred

I would like to match and identify someway

Column A has Bobby Fred Tom
Column B has Fred Tom Bob
That is not a match

I use vlookup to get exact matches. How to get matches if word order is
different?


--

Dave Peterson
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
Combining & formatting cells with text - Excel 2002 Bob Excel Discussion (Misc queries) 4 March 4th 05 10:35 PM
I want Excel to allow cells with formulas and unrelated text blueboy Excel Discussion (Misc queries) 9 March 4th 05 12:22 AM
Format text across cells peterlsutton New Users to Excel 3 February 21st 05 07:54 PM
how do i add the same text after current text in multiple cells Sue Excel Discussion (Misc queries) 3 January 13th 05 09:28 PM
Convert data of cells to any type: Number, Date&Time, Text Kevin Excel Discussion (Misc queries) 0 December 30th 04 06:55 AM


All times are GMT +1. The time now is 03:48 AM.

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

About Us

"It's about Microsoft Excel"