LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default String Comparison

Try the code below:
1. if string1 & string2 match, return true
2. if string1 without last word matches string2 without last word, then


"Purnima" wrote:

Hi..
Thanx for the help.
Is there a way by which I could put each string expression in an array and
then compare them word by word. If all the words match except the last one,
then we could check if it is an abbreviated form of the last word in the
other string expression. Otherwise if all words match ,then that obviously
means that both string expressions are the same.

"AA2e72E" wrote:

Can you restrict the comparison by using just the first letter of the last
word? If , yes, try

Function Compare(ByVal String1 As String, ByVal String2 As String) As Boolean
Compare = UCase(Left(String1, 1 + InStrRev(String1, " "))) =
UCase(Left(String2, 1 + InStrRev(String2, " ")))
End Function

Sub xx()
Debug.Print Compare("ABC SYSTEMS LTD", "abc Systems Inc")
End Sub


"Purnima" wrote:

Hi..
I cannot drop the last word from the comparison. I wish to compare the whole
string
including the last words of both string expressions. The result should be as
follows:

String1 String2
Result

1. ABC Systems Limited ABC Systems Ltd
TRUE

2. ABC Systems Limited ABC Systems Inc.
FALSE

So I need to check whether the last word in one of the string expr. is an
abbreviation of the last word in the other string expr. If it is, then return
true, but if it is a totally different abbr. then return false.


"AA2e72E" wrote:

You might consider dropping the last word from each string before comparing
them:

Function Compare(ByVal String1 As String, ByVal String2 As String) As Boolean
Compare = UCase(Left(String1, InStrRev(String1, " "))) =
UCase(Left(String2, InStrRev(String2, " ")))
End Function

Sub xx()
Debug.Print Compare("ABC SYSTEMS LTD", "abc Systems limited")
End Sub

"Purnima" wrote:

Hi...
I want to perform a comparison on two string expressions. The strings would
normally be of the form "ABC Systems Limited" or "ABC Systems LTD". Now if I
were to compare these two strings, I want the macro to return true even if
the last part of the strings dont match exactly, i.e. Limited and LTD. In
simpler words, it should return true for two strings expressions containing
abbreviations like LTD( Limited), Hlgds( Holdings) etc. Can anyone please
help me with this?

 
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
Comparison of alphanumeric string ErExcel Excel Discussion (Misc queries) 4 May 7th 07 02:14 PM
Text string comparison - closest match pappu Excel Discussion (Misc queries) 1 July 6th 06 04:23 AM
String Comparison & Conditional Formatting Blobbies Excel Discussion (Misc queries) 3 April 18th 06 07:43 AM
comparison string VBA excell stats Excel Discussion (Misc queries) 5 March 16th 06 10:12 PM
VB String Comparison In Excel Craig[_8_] Excel Programming 2 November 24th 03 07:47 PM


All times are GMT +1. The time now is 06:38 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"