+ Reply to Thread
Results 1 to 7 of 7

Find duplicate substring within same cell

  1. #1
    Registered User
    Join Date
    10-16-2012
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    15

    Find duplicate substring within same cell

    Hello guys,

    I've tried to search answer for this tough nut for quite some time already, without a success.


    What should be the formula on Column B in the following case:

    A1 value = "22-25-29---/29-----"
    B1 should return 29

    A2 value = "45-109----/28-45-108---"
    B1 should return 45

    A3 value = "33-46-24-56-/12-23-56-60-"
    B3 should return 56
    and so on....

    I bet this should be done with some kind of array formula or alternatively with VBA.

    Thanks in advance for anyone who could help.

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find duplicate substring within same cell

    Probably should be a VBA solution....but, I saw a formula challenge and had to accept

    With these values in A1:A3
    Please Login or Register  to view this content.
    Each of these solutions (copied down) returns the duplicate value.

    2 helper-cell solution:
    Please Login or Register  to view this content.

    1 helper-cell solution:
    Please Login or Register  to view this content.
    Single Cell solution:
    Please Login or Register  to view this content.
    The returned values are:
    29
    45
    56

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find duplicate substring within same cell

    Also, array formula**:

    =MATCH(TRUE,(LEN("-"&SUBSTITUTE(A1,"/","-"))-LEN(SUBSTITUTE("-"&SUBSTITUTE(A1,"/","-"),"-"&ROW(INDIRECT("1:999"))&"-","")))/(2+LEN(ROW(INDIRECT("1:999"))))>1,0)

    which will work for values up to and including 999. Change this value if required.

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  4. #4
    Registered User
    Join Date
    02-11-2015
    Location
    toronto, canada
    MS-Off Ver
    Office 2013
    Posts
    3

    Re: Find duplicate substring within same cell

    Hi!

    So you have:
    A1 value = "22-25-29---/29-----"
    B1 should return 29

    A2 value = "45-109----/28-45-108---"
    B1 should return 45

    A3 value = "33-46-24-56-/12-23-56-60-"
    B3 should return 56

    What would you like to see from A4 if it contains the following?
    A4 value = "33-46-23-56-/12-23-56-60-"


    Would you want B4 to return 23, or 56? Or both?

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find duplicate substring within same cell

    1) Concise formula....for small duplicate values.
    2) Those darned volatile INDIRECT functions are sluggish for values up to 9999...and they're a show stopper for values up to 999999
    (I tested it on 1000 rows of test values and I had to shut down Excel when it took 5 minutes for the calc meter to increment up to 4%!)

    3) The approach I took, while admittedly inelegant (actually it's as ugly as a mud fence), is surprisingly instantaneous.

    4) I don't envy whoever would need to use either approach!

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find duplicate substring within same cell

    Quote Originally Posted by Ron Coderre View Post
    2) Those darned volatile INDIRECT functions are sluggish for values up to 9999...and they're a show stopper for values up to 999999
    (I tested it on 1000 rows of test values and I had to shut down Excel when it took 5 minutes for the calc meter to increment up to 4%!)
    True. I took a hunch based on the sample data that maybe 3 digits was the maximum string length possible, though if not then of course my solution will certainly become rather resource-heavy!

    Regards

  7. #7
    Registered User
    Join Date
    10-16-2012
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find duplicate substring within same cell

    I was trying to solve this one over an hour earlier today and just couldn't get it together without having 10 helper cells which wouldn't be practical for my purpose.
    It works like a charm


    If you are interested, I need to match filenames with corresponding employees and with your formula I will be able to identify when both Surname and First name have matched on the same row.
    I have only 100 something names in the list so there is very unlikely chanse that both surname and name would be same for two individuals ( Values on left side and right side of the "/" are row matches of names and surnames).


    For example following:
    Names:
    John Smith
    Arnold Smith
    Jessica Pearsson

    Files:
    AC_John_Smith_file908.xlsx
    SA_results_Pearsson_Jessica.xlsx
    Arnold_Smith_survey_results.xlsx



    Thank you one more time. I didn't believe it would be even possible without an Array formula.

+ 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. Loop - Find substring, Change cell value
    By Aardvark1971 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-31-2014, 10:53 PM
  2. Search substring within range, report the substring found
    By Brooke1578 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-20-2012, 03:56 PM
  3. [SOLVED] Extract Substring, then Ignore that Substring, while collecting data from Other substrings
    By Sameki121 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-17-2012, 05:21 PM
  4. Replies: 1
    Last Post: 01-26-2012, 10:06 AM
  5. Find the sub string in column and copy the cell next to the substring
    By shrujan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2009, 11:00 AM

Tags for this Thread

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