+ Reply to Thread
Results 1 to 9 of 9

Help creating a formula to find a substring in a cell to a substring in another cell

  1. #1
    Forum Contributor
    Join Date
    03-15-2016
    Location
    Vancouver, Canada
    MS-Off Ver
    w 10, Excel 2016
    Posts
    125

    Help creating a formula to find a substring in a cell to a substring in another cell

    Hi Formula experts… I need help setting up a formula that will return TRUE (or 1) if these conditions are met...
    In 2 strings where elements (substrings) are separated by commas, see if any one element (substring) is present as an element (substring) in the other string.

    Cell A1 = “A,B,C” -- Cell A2 = “Y,Z,B” = True (B element is in both strings)
    Cell A1 = “A,B,C” -- Cell A2 = “Y,Z,Z” = False (element is in only one string)
    Cell A1 = “A,B,C” -- Cell A2 = “A,B,C” = True (all elements in both strings)

    Is it possible to do with a formula?

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Help creating a formula to find a substring in a cell to a substring in another cell

    try this one:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    with CSE (Control+Shift+Enter)
    or maybe someone else will give you better or shorter solution
    Attached Files Attached Files

  3. #3
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,913

    Re: Help creating a formula to find a substring in a cell to a substring in another cell

    Try this:

    =SUMPRODUCT(COUNTIF(A1,"*"&TRIM(MID(SUBSTITUTE(","&B1,",",REPT(" ",200)),
    ROW(INDIRECT("1:"&LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1))*200,200))&"*"))>0

  4. #4
    Forum Contributor
    Join Date
    03-15-2016
    Location
    Vancouver, Canada
    MS-Off Ver
    w 10, Excel 2016
    Posts
    125

    Re: Help creating a formula to find a substring in a cell to a substring in another cell

    Phuocam and Sandy666. Thanks very much - ingenious. They are so close to what I need. the only challenge with both suggestions is that...

    A1: "A,B,C"
    A2: "AA"

    will return TRUE - where an exact match is needed so should return FALSE. Could either of these suggestions be modified for an exact match?
    Thank you again, really appreciated.

  5. #5
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,913

    Re: Help creating a formula to find a substring in a cell to a substring in another cell

    Try again:

    =COUNT(SEARCH(","&TRIM(MID(SUBSTITUTE(","&B1,",",REPT(" ",200)),ROW(INDIRECT("1:"&LEN(B1)-LEN(SUBSTITUTE(B1,",",""))+1))*200,200))&",",","&A1&","))>0

    Ctrl+Shift+Enter.

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Help creating a formula to find a substring in a cell to a substring in another cell

    Quote Originally Posted by Andrew Entee View Post
    In 2 strings where elements (substrings) are separated by commas, see if any one element (substring) is present as an element (substring) in the other string.

    Cell A1 = “A,B,C” -- Cell A2 = “Y,Z,B” = True (B element is in both strings)
    Cell A1 = “A,B,C” -- Cell A2 = “Y,Z,Z” = False (element is in only one string)
    Cell A1 = “A,B,C” -- Cell A2 = “A,B,C” = True (all elements in both strings)
    so your example is not correct
    it should reflect structure and all possible values
    Last edited by sandy666; 03-02-2018 at 07:47 PM.

  7. #7
    Forum Contributor
    Join Date
    03-15-2016
    Location
    Vancouver, Canada
    MS-Off Ver
    w 10, Excel 2016
    Posts
    125

    Re: Help creating a formula to find a substring in a cell to a substring in another cell

    Brilliant!, That's it! Thank you very much!

  8. #8
    Forum Contributor
    Join Date
    03-15-2016
    Location
    Vancouver, Canada
    MS-Off Ver
    w 10, Excel 2016
    Posts
    125

    Re: Help creating a formula to find a substring in a cell to a substring in another cell

    Phuocam - I thought we had it, but I've noticed that

    A1 = aa,bb,cc
    A2 = cc
    returns FALSE... but...

    A1 = cc,aa,bb
    A2 = cc
    returns TRUE (which is correct) - so seems that it is not picking up the last position for a match. Any help is very much appreciated.

  9. #9
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,567

    Re: Help creating a formula to find a substring in a cell to a substring in another cell

    I can not replicate your problem. I put the values in cells A1 and A2 as given in post #8 and got True in both instances. Even when I entered the formula (modified as the original was written to test A1 and B1) using only the Enter key I still got True in both instances. Perhaps if you could upload a sample file that shows the formula yielding the result you got in the instance shown at the top of post #8 we may be able to sort out what is going on.

    To attach a sample file, click on the GO ADVANCED button below the Quick Reply window and then scroll down to Manage Attachments to open the upload window.
    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ 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. 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
  2. Find duplicate substring within same cell
    By kingoftheace in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-11-2015, 05:04 PM
  3. Loop - Find substring, Change cell value
    By Aardvark1971 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-31-2014, 10:53 PM
  4. 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
  5. [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
  6. sum a value(substring) in a cell
    By tnchong in forum Excel - New Users/Basics
    Replies: 17
    Last Post: 05-18-2009, 03:55 AM
  7. 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

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