+ Reply to Thread
Results 1 to 19 of 19

Find out the length of common string between cells of two columns.

  1. #1
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Find out the length of common string between cells of two columns.

    Hi all ,

    I have a problem where I need to find out the common intersection string between two cells of adjacent columns and find its length .

    something like F2 = length ("D2" intersection "E2")

    D2 = Tommy Hilfiger Bohemian Dress
    E2 = Tommy Hilfiger Hawaaian Dress

    D2 intersection E2 will be Tommy Hilfiger Dress

    the column F2 should be filled with value of 19 which is length of intersection string


    I want to do this for whole columns D and E.

    Thanks in advance.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Find out the length of common string between cells of two columns.

    You need to provide more information on what exactly defines an intersection.

    D2 = Tommy Hilfiger Red Dress
    E2 = Tommy Hilfiger Green Dress

    Would the above still result in 19?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Find out the length of common string between cells of two columns.

    Try this :

    Please Login or Register  to view this content.
    Please remember to click the * below if this helps
    Please click the * below if this helps

  4. #4
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Find out the length of common string between cells of two columns.

    Thanks Jasper .. I will try testing it now

  5. #5
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Find out the length of common string between cells of two columns.

    Quote Originally Posted by Andy Pope View Post
    You need to provide more information on what exactly defines an intersection.

    D2 = Tommy Hilfiger Red Dress
    E2 = Tommy Hilfiger Green Dress

    Would the above still result in 19?
    Yes Andy technically it should just return the length of common words . Its okay if we ignore the spaces .. My goal is to find out how different is the string in column E from column D .. so then il again compare the common string result with the string in column D and then analyze

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Find out the length of common string between cells of two columns.

    I still think your spec is too vauge.

    D2 = Tommy Hilfiger Dress Red
    E2 = Tommy Hilfiger Green Dress

    Does this still return 19?

    So is this just a duplicate word count function, or is the order of the words important?

  7. #7
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Find out the length of common string between cells of two columns.

    Okay let me explain the problem clearly .

    Column D has string that is copied into column E and few changes are done on that string. Technically both the strings will be closely similar . Due to manually copying and pasting information in column E , there has been few row mis-matches so I want to find out which rows have been mis matches . For that I though comparing the string length of column D with that of the intersection length and sorting that comparison number should give me a fair idea where the mis matches are . I will devise a way to find mis matches.

    I am adding sample data


    data.xlsx

    Thanks in advance

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Find out the length of common string between cells of two columns.

    why not simply use =D2=E2 and then filter on FALSE

  9. #9
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Find out the length of common string between cells of two columns.

    No because they wont be technically equal .. the data in E2 is altered a bit .. not very much but slightly. Most of the string would be similar but not totally equal .

  10. #10
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Find out the length of common string between cells of two columns.

    @jasper

    Thanks a lot your code works just fine ...and yes clicked the star

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Find out the length of common string between cells of two columns.

    this array formula will tell you when the text goes out of sync

    =MIN(IF(MID(D2,ROW(1:100),1)<>MID(E2,ROW(1:100),1),ROW(1:100),999))

  12. #12
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Find out the length of common string between cells of two columns.

    Quote Originally Posted by JasperD View Post
    Try this :

    Please Login or Register  to view this content.
    Please remember to click the * below if this helps
    Hi jasper I have tested this code. Few issues i found out were The intersection of strings was not being calculated if both of them started with different words .

    example "One good man was there" and "A good man was there" the result must be 15 excluding the count of spaces . But this code gives me result of 0 .

    It would be great if this can be fixed some how ! Thanks in advance

  13. #13
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Find out the length of common string between cells of two columns.

    Ok, let me alter that (it's not impossible, just a b*tch).

    What outcome do you expect on :
    "One good man was there" vs "A good man was there yesterday"

    and on :
    "Apple, Banana, Orange, Pear" vs "Cat, Fish, Banana, Dog"

    Thanks
    Last edited by JasperD; 08-27-2013 at 09:21 AM.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,569

    Re: Find out the length of common string between cells of two columns.

    Try this
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Find out the length of common string between cells of two columns.

    @Jasper

    "One good man was there" vs "A good man was there yesterday" Expected result = len(good man was there) = 18

    "Apple, Banana, Orange, Pear" vs "Cat, Fish, Banana, Dog" Expected result = len(Banana) = 6

  16. #16
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Find out the length of common string between cells of two columns.

    Quote Originally Posted by jindon View Post
    Try this
    Please Login or Register  to view this content.
    Thanks Jindon it works but then i run into Run-time error '5018':
    Application-defined or object-defined error at line
    "For Each m In .Execute(r(, 2).Value)"

    and the code execution stopped . One reason i identified it happened was because of + sign in the D column I eliminated all the + signs and when "(" is present in the D column works fine if i have "(" and ")" in the same cell but then again the code gave an error for the string

    Got Gray? Bodysuit Vs Idakoos Unisex-baby "Got Gray?" Bodysuit

    Can you fix this problem ? I will attach my sample datasample data.xlsx

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,569

    Re: Find out the length of common string between cells of two columns.

    rampulaparthi

    Change to
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Find out the length of common string between cells of two columns.

    Thanks a lot Jindon !! you helped me a lot !!

  19. #19
    Registered User
    Join Date
    06-20-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Find out the length of common string between cells of two columns.

    @jindon

    Sorry for bothering you so much but theres a problem when i test this code ... I have attached sample data .. its giving significant count even when theres no matching between strings

    Error sample data.xlsx

    This problem is arising only after the modification you made .. else it was working fine ...

    Before this line was added

    .Pattern = "([\$\(\)\-\^\|\\\[\]\*\+\?\.\?])"

    Thanks again for being patient with my questions
    Last edited by rampulaparthi; 08-28-2013 at 03:20 AM.

  20. #20
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,569

    Re: Find out the length of common string between cells of two columns.

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to find common string column from two columns??
    By sanil.henry1982 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2012, 08:34 AM
  2. [SOLVED] URGENT find common string values in 2 colums
    By M.Karim in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-13-2012, 11:21 AM
  3. how to write macro to find and match common string and write the keyword
    By narendrabr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-16-2012, 07:41 AM
  4. How to find the pixel length of a string
    By johnjohns in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-18-2011, 10:01 AM
  5. Find the lest common string-value in a range
    By ElmerS in forum Excel General
    Replies: 4
    Last Post: 02-01-2009, 06:25 PM

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