+ Reply to Thread
Results 1 to 3 of 3

Common substring

  1. #1
    Registered User
    Join Date
    02-22-2019
    Location
    Fairfax, VA & SF, CA
    MS-Off Ver
    Pro 2019
    Posts
    6

    Common substring

    Hey all,

    First post here!

    My issue is that I'm trying to find the most common substring in a list of strings.

    So if my data set was:

    1. AMZN MKTP US*M06TK6Y01 AMZN.C AMZN MKTP US*M06TK6Y01
    2. Amazon.com*M28R03BA0 Amzn.c Amazon.com*M28R03BA0
    3. Amazon.com*M255Q4E62 Amzn.c Amazon.com*M255Q4E62
    4. Amazon.com*MB5OT5BL0

    It would return amzn.c

    And if my set was

    1. ADOBE *ACROPRO SUBS 800833
    2. ADOBE *ACROPRO SUBS 800833 ADOBE *ACROPRO SUBS
    3. ADOBE *ACROPRO SUBS 800833 ADOBE *ACROPRO SUBS
    4. ADOBE *ACROPRO SUBS

    It would return ADOBE *ACROPRO SUBS


    I've used a couple different Macros that can pull a common substrings from 2 cells but can't seem to have it pull from an entire array.

    Been working on this forever and cannot for the life of me figure it out...

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Common substring

    In your first example, why isn't the most common substring "Amazon.com*M"? It occurs 5 times. AMZN.C only occurs 3 times.

    Does a substring have to be a whole "word" (i.e., delimited by spaces) or can it be embedded in other strings?

    This is quite a difficult problem, by the way.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    02-22-2019
    Location
    Fairfax, VA & SF, CA
    MS-Off Ver
    Pro 2019
    Posts
    6

    Re: Common substring

    That's my mistake! I forgot to add the amzn.c to the 4th line. You are correct though that amzn.com would still appear less times than amazon.com*m.

    In this case I would be more interested in the string that appears in each individual line most often, rather than the string that appears the most times in the entire array.

    Not sure I explained it that well, as an example the first array I provided (given the addition of amzn.c at the end), would have 4 unique lines that contained "amzn.c" but only 3 unqiue lines that contain amazon.com*. Regardless, either option would probably work in this case.

    The substring can absolutely be embedded within other strings. If you'd like an example of the application of this I'd be happy to provide more information.

    Its something that has stumped me for a long time which is why I reached out here :/

    Thanks for any help here!

+ 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. Replies: 8
    Last Post: 03-09-2018, 11:39 AM
  2. Macro to search cells for substring and replace contents of cell if substring is found
    By robbyvegas in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2015, 06:40 AM
  3. Return most common, 2nd common...within the data range
    By tantcu in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-07-2015, 06:06 PM
  4. Replies: 1
    Last Post: 09-26-2014, 04:47 PM
  5. 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
  6. [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
  7. Finding the most common (and 2nd, 3rd most common) text
    By sprite_green in forum Excel General
    Replies: 2
    Last Post: 11-23-2006, 11:56 AM

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