PC Review


Reply
Thread Tools Rate Thread

Compare text string of a cell in Column A VS another cell in Colum

 
 
=?Utf-8?B?VGFu?=
Guest
Posts: n/a
 
      30th Jul 2007
Hi All,

I would appreciate greatly if any vba expert could help me with this
solutioning urgently as my deadline is drawing near (today) and i could not
resolve this solution for cell comparison.

I have a vba function code below written in such a way that it compares a
cell in Column A versus another cell in Column B. But both cells must be the
same row in order to compare. Say cell A2 contains "M O E" and cell B2
contains "Ministry of Education" and my function in cell C2 which is =
Fuzzy(A2,B2), will give me 100% correct percentages. The other example is
where A2 contains "3M" and cell B2 contains "3M Korea" and also returns 100%.

I needs someone to advice me how there is any way i could re-code my
solution such that if "3M" is in any cell in Column A say A150 and "3M Korea"
is in say cell B55 under column B. End results is both cell A150 and B55
matches by means of colored cell as it is 100% correct. Also it must not case
sensitive during matching.
Thanks in advance...


Below is my old code:

Dim TopMatch As Integer
Dim strCompare As String
Function Fuzzy(strIn1 As String, strIn2 As String) As Single
Dim L1 As Integer
Dim In1Mask(1 To 24) As Long 'strIn1 is 24 characters max
Dim iCh As Integer
Dim N As Long
Dim strTry As String
Dim strTest As String

TopMatch = 0
L1 = Len(strIn1)
strTest = UCase(strIn1)
strCompare = UCase(strIn2)

For iCh = 1 To L1
In1Mask(iCh) = 2 ^ iCh
Next iCh

'Loop thru all ordered combinations of characters in strIn1
For N = 2 ^ (L1 + 1) - 1 To 1 Step -1
strTry = ""
For iCh = 1 To L1
If In1Mask(iCh) And N Then
strTry = strTry & Mid(strTest, iCh, 1)
End If
Next iCh
If Len(strTry) > TopMatch Then TestString strTry
Next N

Fuzzy = TopMatch / CSng(L1)

End Function
Sub TestString(strIn As String)
Dim L As Integer
Dim strTry As String
Dim iCh As Integer

L = Len(strIn)
If L <= TopMatch Then Exit Sub

strTry = "*"

For iCh = 1 To L
strTry = strTry & Mid(strIn, iCh, 1) & "*"
Next iCh

If strCompare Like strTry Then
If L > TopMatch Then TopMatch = L
End If

End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
FIND / SEARCH text compare cell to string in 3rd cell =?Utf-8?B?bmFzdGVjaA==?= Microsoft Excel Misc 0 29th Oct 2007 02:51 AM
Compare text string of a cell in Column A VS another cell in Colum =?Utf-8?B?VGFu?= Microsoft Excel New Users 2 1st Aug 2007 09:45 AM
Compare text string of a cell in Column A VS another cell in Colum =?Utf-8?B?VGFu?= Microsoft Excel Misc 1 1st Aug 2007 09:03 AM
Compare text string of a cell in Column A VS another cell in Colum =?Utf-8?B?VGFu?= Microsoft Excel Worksheet Functions 1 1st Aug 2007 09:01 AM
How do I read cell value and compare it with other cell in a colum =?Utf-8?B?bHBkYXJzcGU=?= Microsoft Excel Programming 8 6th Apr 2006 07:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:40 PM.