Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Find similar items from a two fields.

Hi,

I am really in a tight spot now.

I need macro which will compare two strings if they are similar.

For example:
StringA = I-11524A
StringB = I-11525B
StringC = I-11525

Now these three string are similar and need a utility which will compare
these strings and highlight them if they are similar.
I tried two three codes like StrComp(str1, str2, vbTextCompare) but it did
not work.

Kindly help.

Regards
Heera Chavan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Find similar items from a two fields.

You can check for the first n characters (based on the sepcification and your
requirement) using either LEFT() or using LIKE()...

Dim str1 As String
Dim str2 As String

str1 = "I-11524A"
str2 = "I-11525B"

If str1 Like Left(str2, 6) & "*" Then
MsgBox "Similar"
End If


If this post helps click Yes
---------------
Jacob Skaria


"Heera Chavan" wrote:

Hi,

I am really in a tight spot now.

I need macro which will compare two strings if they are similar.

For example:
StringA = I-11524A
StringB = I-11525B
StringC = I-11525

Now these three string are similar and need a utility which will compare
these strings and highlight them if they are similar.
I tried two three codes like StrComp(str1, str2, vbTextCompare) but it did
not work.

Kindly help.

Regards
Heera Chavan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Find similar items from a two fields.

I need to write a long script for this...any way I am writing a script with
the help of worksheet function SEARCH which is quite similar to your
idea......

Thank you for your support.

"Jacob Skaria" wrote:

You can check for the first n characters (based on the sepcification and your
requirement) using either LEFT() or using LIKE()...

Dim str1 As String
Dim str2 As String

str1 = "I-11524A"
str2 = "I-11525B"

If str1 Like Left(str2, 6) & "*" Then
MsgBox "Similar"
End If


If this post helps click Yes
---------------
Jacob Skaria


"Heera Chavan" wrote:

Hi,

I am really in a tight spot now.

I need macro which will compare two strings if they are similar.

For example:
StringA = I-11524A
StringB = I-11525B
StringC = I-11525

Now these three string are similar and need a utility which will compare
these strings and highlight them if they are similar.
I tried two three codes like StrComp(str1, str2, vbTextCompare) but it did
not work.

Kindly help.

Regards
Heera Chavan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Find similar items from a two fields.

Try the below....which will compare the numeric pieces alone..

Sub Macro()

Dim str1 As String
Dim str2 As String

str1 = "I-11524A"
str2 = "I11524B"

If GetNumericString(str1) = GetNumericString(str2) Then
MsgBox "Similar"
End If

End Sub

Function GetNumericString(strData As String) As String
For inttemp = 1 To Len(strData)
If IsNumeric(Mid(strData, inttemp, 1)) Then
GetNumericString = GetNumericString & Mid(strData, inttemp, 1)
End If
Next
End Function

If this post helps click Yes
---------------
Jacob Skaria


"Heera Chavan" wrote:

I need to write a long script for this...any way I am writing a script with
the help of worksheet function SEARCH which is quite similar to your
idea......

Thank you for your support.

"Jacob Skaria" wrote:

You can check for the first n characters (based on the sepcification and your
requirement) using either LEFT() or using LIKE()...

Dim str1 As String
Dim str2 As String

str1 = "I-11524A"
str2 = "I-11525B"

If str1 Like Left(str2, 6) & "*" Then
MsgBox "Similar"
End If


If this post helps click Yes
---------------
Jacob Skaria


"Heera Chavan" wrote:

Hi,

I am really in a tight spot now.

I need macro which will compare two strings if they are similar.

For example:
StringA = I-11524A
StringB = I-11525B
StringC = I-11525

Now these three string are similar and need a utility which will compare
these strings and highlight them if they are similar.
I tried two three codes like StrComp(str1, str2, vbTextCompare) but it did
not work.

Kindly help.

Regards
Heera Chavan

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Find similar items from a two fields.

Heera, you can further customize this to check for the first n numerics; but
that is to be finalized based on your requirement...Analyse more samples and
you can addup more validations to that..

'to compare the 1st 4 numerics

Left(GetNumericString(str1),4) = Left(GetNumericString(str2),4)

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Try the below....which will compare the numeric pieces alone..

Sub Macro()

Dim str1 As String
Dim str2 As String

str1 = "I-11524A"
str2 = "I11524B"

If GetNumericString(str1) = GetNumericString(str2) Then
MsgBox "Similar"
End If

End Sub

Function GetNumericString(strData As String) As String
For inttemp = 1 To Len(strData)
If IsNumeric(Mid(strData, inttemp, 1)) Then
GetNumericString = GetNumericString & Mid(strData, inttemp, 1)
End If
Next
End Function

If this post helps click Yes
---------------
Jacob Skaria


"Heera Chavan" wrote:

I need to write a long script for this...any way I am writing a script with
the help of worksheet function SEARCH which is quite similar to your
idea......

Thank you for your support.

"Jacob Skaria" wrote:

You can check for the first n characters (based on the sepcification and your
requirement) using either LEFT() or using LIKE()...

Dim str1 As String
Dim str2 As String

str1 = "I-11524A"
str2 = "I-11525B"

If str1 Like Left(str2, 6) & "*" Then
MsgBox "Similar"
End If


If this post helps click Yes
---------------
Jacob Skaria


"Heera Chavan" wrote:

Hi,

I am really in a tight spot now.

I need macro which will compare two strings if they are similar.

For example:
StringA = I-11524A
StringB = I-11525B
StringC = I-11525

Now these three string are similar and need a utility which will compare
these strings and highlight them if they are similar.
I tried two three codes like StrComp(str1, str2, vbTextCompare) but it did
not work.

Kindly help.

Regards
Heera Chavan



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Find similar items from a two fields.


Thank you....Jocob.....your macro is working fine.....
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Find similar items from a two fields.

Can you describe what you mean by "similar"?

--
Rick (MVP - Excel)


"Heera Chavan" wrote in message
...
Hi,

I am really in a tight spot now.

I need macro which will compare two strings if they are similar.

For example:
StringA = I-11524A
StringB = I-11525B
StringC = I-11525

Now these three string are similar and need a utility which will compare
these strings and highlight them if they are similar.
I tried two three codes like StrComp(str1, str2, vbTextCompare) but it did
not work.

Kindly help.

Regards
Heera Chavan


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Find similar items from a two fields.

Hi Rick,

I want to compare two invoice numbers which are same but one or two
character here and there. The diffrence might be because of one "-" or an "*"
is extra in one of the strings or else one number is missing from the left or
the right side of the string.........

I want a robust macro which will compare all this things.....

If you alreday have some thing please, please let me know......

Regards
Heera Chavan

"Rick Rothstein" wrote:

Can you describe what you mean by "similar"?


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Find similar items from a two fields.

So are you saying that these would all be "similar"?

I-11524A
I-99524A
M-11524A
Z-12924A
etc.

--
Rick (MVP - Excel)


"Heera Chavan" wrote in message
...
Hi Rick,

I want to compare two invoice numbers which are same but one or two
character here and there. The diffrence might be because of one "-" or an
"*"
is extra in one of the strings or else one number is missing from the left
or
the right side of the string.........

I want a robust macro which will compare all this things.....

If you alreday have some thing please, please let me know......

Regards
Heera Chavan

"Rick Rothstein" wrote:

Can you describe what you mean by "similar"?



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Find similar items from a two fields.

No here is an example.....

I-11524A would be similar with I11524A, I -11524B, I-111524A I- 11524A
B-115253 would be similar with B115253, B1115253, B115253-A, B-115253B

Like this.........thank you for the response.

"Rick Rothstein" wrote:

So are you saying that these would all be "similar"?

I-11524A
I-99524A
M-11524A
Z-12924A
etc.

--
Rick (MVP - Excel)


"Heera Chavan" wrote in message
...
Hi Rick,

I want to compare two invoice numbers which are same but one or two
character here and there. The diffrence might be because of one "-" or an
"*"
is extra in one of the strings or else one number is missing from the left
or
the right side of the string.........

I want a robust macro which will compare all this things.....

If you alreday have some thing please, please let me know......

Regards
Heera Chavan

"Rick Rothstein" wrote:

Can you describe what you mean by "similar"?



.



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Find similar items from a two fields.

Nice examples Rick..

"Rick Rothstein" wrote:

So are you saying that these would all be "similar"?

I-11524A
I-99524A
M-11524A
Z-12924A
etc.

--
Rick (MVP - Excel)


"Heera Chavan" wrote in message
...
Hi Rick,

I want to compare two invoice numbers which are same but one or two
character here and there. The diffrence might be because of one "-" or an
"*"
is extra in one of the strings or else one number is missing from the left
or
the right side of the string.........

I want a robust macro which will compare all this things.....

If you alreday have some thing please, please let me know......

Regards
Heera Chavan

"Rick Rothstein" wrote:

Can you describe what you mean by "similar"?



.

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Find similar items from a two fields.


Try this out - it has sample VB code at the bottom of the page.

http://www.merriampark.com/ld.htm

Tim


On Nov 12, 11:07*pm, Heera Chavan
wrote:
Hi,

I am really in a tight spot now.

I need macro which will compare two strings if they are similar.

For example:
StringA = I-11524A
StringB = I-11525B
StringC = I-11525

Now these three string are similar and need a utility which will compare
these strings and highlight them if they are similar.
I tried two three codes like StrComp(str1, str2, vbTextCompare) but it did
not work.

Kindly help.

Regards
Heera Chavan


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Find similar items from a two fields.


Tim this code was simply great..............thank a ton...............
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
Using the lookup Function for similar items to add together Brian Excel Worksheet Functions 1 July 13th 06 05:23 AM
using macro, how can i copy similar fields from other xls files? Shaji Valiath Excel Discussion (Misc queries) 0 May 23rd 06 09:56 AM
Grouping Similar items crosswire123 Excel Worksheet Functions 3 March 31st 06 08:54 PM
counting similar items in a column bj Excel Discussion (Misc queries) 5 June 6th 05 10:30 PM
Counting groups of similar items Jason[_30_] Excel Programming 11 June 23rd 04 12:58 AM


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