+ Reply to Thread
Results 1 to 8 of 8

String Comparision

  1. #1
    Registered User
    Join Date
    07-14-2008
    Location
    INDIA
    Posts
    78

    String Comparision

    Hi,

    I am having my data from A1:A1000 in which I want to know if there are any repeatitions. The problem is that the order of words may not be same. For example strings "I am fine" and "Fine I am" are to be recognised as repeatitions.

    Can anyone out there help me to make my task easy by giving me a macro.

    Thank you.
    Last edited by VBA Noob; 11-10-2008 at 09:18 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello TRJJK73,

    Please include a link in your post when you have posted the same question in another forum. You posted this same question at MrExcel...

    http://www.mrexcel.com/forum/showthread.php?t=352028

    Please read the forum rules to refresh your memory.

    Sincerely,
    Leith Ross

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Hi TRJJK73,

    Well, without using some interesting VBA, this might get you at least close to what you're after. The array formula shown below will sum the CODE values of all characters in a cell. This will give you a number, that, while not guaranteed to be unique, will definitely allow you to narrow down any potential matches.

    With your list in A1:A1000, put this formula into B1 and fill it down to B1000 (remember that since it's an array formula, after typing it you must press CTRL+SHIFT+ENTER, not just ENTER!):

    =SUM(CODE(MID(UPPER(A1),ROW(INDIRECT("1:"&LEN(UPPER(A1)))),1)))

    Now if you sort columns A and B by column B, any duplicates in column B *could* be a match of words in a cell. I say could because two cells, while containing different words, might use the same exact letters, numbers and spacing which would create a sum equal to another string using those same characters in different words.

    The rat meat = THE RAT MEAT = 815
    Tame the rat = TAME THE RAT = 815
    Tar the team = TAR THE TEAM = 815

    Notice all three cells result in 815 because they use the exact same letters and number of spaces, but their words do not match. This is the distinction you would need to make to identify true matches. I don't foresee you having an abundance of cells that fit this scenario, but it could happen on occasion.

    Duplicate sums could also occur with words that don't even share the same letters. For example, the sum of the codes for the words DATE (68,65,84,69=286) is the same as HEAP (72,65,69,80=286). With multiple words per cell, the likeliness of two matches is probably small once again.

    Try it and let us know!
    Last edited by Paul; 11-08-2008 at 02:07 AM.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    This UDF might help.
    =CountDisorderedWordMatch("I am Fine",A1:A100) will return how many cells in A1:A100 have the same words as "I am Fine".
    The match is case insensitive and word order insensitive.
    "I am Fine" matches "fine I am", but matches neither "I am very fine" nor "I am fine."

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    more info needed

    Hi
    Can you post a sample workbook?How much of match would you consider as identical? (if 9 words out of 10 are same / need to be 10 but in any order)
    Ravi

  6. #6
    Registered User
    Join Date
    07-14-2008
    Location
    INDIA
    Posts
    78

    String Comparision

    Quote Originally Posted by ravishankar View Post
    Hi
    Can you post a sample workbook?How much of match would you consider as identical? (if 9 words out of 10 are same / need to be 10 but in any order)
    Ravi
    Hi Ravi and mikerickson,

    I have attached a sample sheet in which 1,2,3 are same and again 7&8 are same. Instead of UDF can I have a macro which highlights the repeated cells.

    It will be perfect if it is 10/10.

    Thank you.
    Attached Files Attached Files

  7. #7
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, Try this:-
    Data in Column "A".
    Results in Msgbox.
    Please Login or Register  to view this content.
    Regards Mick

  8. #8
    Registered User
    Join Date
    07-14-2008
    Location
    INDIA
    Posts
    78
    Hi MickG,
    Thank you very much. Its working perfectly.

    Regards,
    TRJJK73.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1