+ Reply to Thread
Results 1 to 12 of 12

Returning one Value contained in a List

  1. #1
    Registered User
    Join Date
    10-20-2021
    Location
    Canada
    MS-Off Ver
    Microsoft Excel for Office 365 MSO - desktop version
    Posts
    16

    Returning one Value contained in a List

    Hi, I have a list of data in column G containing multiple values seperated by commas.
    I want to reference a list in column B and then if a value in that list is located in the cell in Column G, I want it to return that value.
    For example, my list is made up of the following values, red, red ball, red pen, make, shift, computer.
    I then want it to look at my cell in column G and return only 1 value based on the most appropriate match.
    If the cell in column G, contains the values red ball, walk, show, tent, invade. I just want it to return 'red ball', rather than both 'red' and red ball.

    I have tried multiple formulas but no luck yet.
    =TEXTJOIN(", ",TRUE,IF(COUNTIF(G2,"*"&$B$2:$B$10&"*"),$B$2:$B$10,"")) - This will return all values seperated by a comma

    =IF(OR(INDEX(COUNTIF(G2,"*"&($B$2:$B$10)&"*"),)),$B$2:$B$10,"") - This doesnt seem to work because it doesnt know which value to return.

    Any help would be much appreciated.
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,944

    Re: Returning one Value contained in a List

    This gets it down to two relevant items (removing the blanks). If one entry is a subset of the other(s), I can't see how you will get it down to a single entry.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    03-05-2018
    Location
    Tbilisi, Georgia
    MS-Off Ver
    2013, 2016
    Posts
    273

    Re: Returning one Value contained in a List

    I think, I've got a solution.
    PHP Code: 
    =INDEX($B$2:$B$7,SMALL(IF(ISNUMBER(SEARCH($B$2:$B$7&",",$G$2&","))*(ROW($B$2:$B$7)-1)>0,ROW($B$2:$B$7)-1),ROW(A1))) 
    Array formula confirmed with CTRL+SHIFT+ENTER for older versions of Excel. OR...
    PHP Code: 
    =INDEX($B$2:$B$7,AGGREGATE(15,6,ROW($A$1:$A$10)/(ISNUMBER(SEARCH($B$2:$B$7&",",$G$2&","))*(ROW($B$2:$B$7)-ROW($B$1)+1)>0),ROW(A1))) 
    Capture.PNG
    Attached Files Attached Files
    Last edited by T.I.; 10-20-2021 at 07:46 PM.

  4. #4
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Returning one Value contained in a List

    Here is a slightly different attempt

    I made the same assumption as Strogg, in that if there is more than a single match then each match is listed in subsequent rows.

    In E2 copied down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Strogg: Assuming that we're on the right track at all, there may be a minor issue with your formula in that if there is a prefix to any of the words in G2 then your formula still sees a match. For example, changing "make" in G2 to "matchmake" will still be seen as a match to "make" in col-B.

    wordmatch.png
    Attached Files Attached Files
    Geoff

    Did I help significantly? If you wish, click on * Add Reputation to say thanks.
    If your problem has been resolved please select ?Solved? from the Thread Tools menu

  5. #5
    Forum Contributor
    Join Date
    03-05-2018
    Location
    Tbilisi, Georgia
    MS-Off Ver
    2013, 2016
    Posts
    273

    Re: Returning one Value contained in a List

    Quote Originally Posted by GeoffW283
    Strogg: Assuming that we're on the right track at all, there may be a minor issue with your formula in that if there is a prefix to any of the words in G2 then your formula still sees a match. For example, changing "make" in G2 to "matchmake" will still be seen as a match to "make" in col-B.
    Thank you. Yesterday, first I was trying to do it in an almost similar way, but missed an option with the MATCH function.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,794

    Re: Returning one Value contained in a List

    If, as the title suggests, there will only ever be ONE value to return, then this should work:

    =IFERROR(LOOKUP(1000,SEARCH($B$2:$B$7,G2),$B$2:$B$7),"")
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  7. #7
    Registered User
    Join Date
    10-20-2021
    Location
    Canada
    MS-Off Ver
    Microsoft Excel for Office 365 MSO - desktop version
    Posts
    16

    Re: Returning one Value contained in a List

    Hi Geoff/ Strogg,

    Thank you both, that is both a massive help.
    I am just wondering is there a way of altering the formula so that it only returns one answer per line so that it then can be dragged down and made applicable to each line.
    For example, I have put my ideal output in Column I, which corresponds to the list in Column B.
    SO it wouldnt return any value in I2 because 'red' is not an exact match, it would have to be 'red ball'. I am not sure if this is possible.

    Thanks again to both of you for your help.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    10-20-2021
    Location
    Canada
    MS-Off Ver
    Microsoft Excel for Office 365 MSO - desktop version
    Posts
    16

    Re: Returning one Value contained in a List

    Hi Ali,
    there could be a few different variations in the list and I am wondering can it return the most applicable result based on that current line. SO your example seems to return 'computer' for each line. Whereas I would only want it to return computer on the line where computer is within the list. I also need it to return 'red ball' on the line where that is present and then blanks for everything else

    Thanks

  9. #9
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Returning one Value contained in a List

    OK, here is a modification to the formula that I think does what you want. In J2 copied down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    See the attached workbook.
    Attached Files Attached Files
    Last edited by GeoffW283; 10-21-2021 at 02:58 PM.

  10. #10
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Returning one Value contained in a List

    Another attempt - same result but a significantly simpler formula. In K2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    For those without O-365, this is an array formula and must be committed via CTRL-SHIFT_ENTER.
    Copy K2 down as far as needed.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    03-05-2018
    Location
    Tbilisi, Georgia
    MS-Off Ver
    2013, 2016
    Posts
    273

    Re: Returning one Value contained in a List

    And one more option, almost the same as above.
    PHP Code: 
    =IF(AGGREGATE(14;6;N(TRIM(MID(SUBSTITUTE($G$2;",";REPT(" ";99));(ROW($A$1:$A$20)-1)*98+1;99))=B2);1);B2;""
    Attached Files Attached Files

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,944

    Re: Returning one Value contained in a List

    My apologies, I thought I posted the formula but it seems to have got lost in the post.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Seems to work unless one word is a subset of another phrase, for example, red and red ball, or red and red pen, will retur both entries.

+ 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. If contained in the list return value
    By lilit2222 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-20-2021, 09:59 AM
  2. Replies: 2
    Last Post: 05-13-2021, 01:37 PM
  3. [SOLVED] Looking for a formula that indicates text not contained in a list.
    By Travisty in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 10-20-2015, 09:58 AM
  4. Replies: 4
    Last Post: 07-28-2015, 01:54 PM
  5. Sum if a number is contained in a list
    By pauldaddyadams in forum Excel General
    Replies: 8
    Last Post: 12-03-2013, 02:30 PM
  6. List based on value contained in cell
    By Steve_Courts in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-06-2009, 08:07 PM
  7. Looking up whether a value is contained in an unsorted list of strings
    By lordhed in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 04-01-2007, 07:51 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