+ Reply to Thread
Results 1 to 10 of 10

search multiple words in a cell and output what the cell contains

  1. #1
    Registered User
    Join Date
    09-05-2019
    Location
    NY, NY
    MS-Off Ver
    16.28
    Posts
    3

    search multiple words in a cell and output what the cell contains

    Hi,

    I have 5 different words that can be combined in every which way. I have a list of cells that have these words combined and/or repeated. I want to search a cell to see if it has any, all, or some of the 5 words and spit it back out in a cleaner manner (preferably alphabetically). I've tried an if/isnumber/search formulas and it usually just spits out the first word in the cell rather than scanning the rest of the cell to see if it has additional words in it.

    Example:

    words: apple, cat, dog, orange, pear

    apple,dog,apple,dog,cat > apple, cat, dog
    orange,apple,dog > apple, dog, orange
    orange,orange > orange
    orange,apple,apple,dog,cat,pear,pear > apple, cat, dog, orange, pear
    pear,orange > pear, orange
    pear,orange,orange,cat > cat, orange, pear

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: search multiple words in a cell and output what the cell contains

    Have you tried incorporating an OR statement with the IF/ISNUMBER/SEARCH for each?
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: search multiple words in a cell and output what the cell contains

    It would help us to help you, if you can upload sample workbook that mirror your set up.

    What you are trying to do can be achieved using several methods, but exact process will depend on your data structure/workbook set up.

    1. Using PowerQuery(Get & Transform) - My preferred method, good GUI, as well as preview of each intermediate steps. But may not be suitable if you need backward compatibility beyond Excel 2010/13.
    2. Using VBA/UDF - May be difficult to modify, if not familiar with it. Especially if scope changes.
    3. Formula - Exact construct will depend on data layout, and how the results should be structured.


    To upload, use "Go Advanced" button, follow "Manage Attachments" hyperlink. It will launch new tab/window for managing uploads.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: search multiple words in a cell and output what the cell contains

    This is one way for data starting "A2" and Criteria in code (txt), Results in column "B".
    Please Login or Register  to view this content.
    Regards Mick

  5. #5
    Registered User
    Join Date
    09-05-2019
    Location
    NY, NY
    MS-Off Ver
    16.28
    Posts
    3

    Re: search multiple words in a cell and output what the cell contains

    Thanks for the answers. I've attached a test book with a couple of manually filled out rows so you get the idea. Looking forward to some more input.
    Attached Files Attached Files

  6. #6
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: search multiple words in a cell and output what the cell contains

    this is so close, the problem is that it leaves a trailing comma for any of them that do not end with pear. So for your first example, it returns apple, orange,

    =IF(ISNUMBER(SEARCH("apple",B2)),"apple, ","")&IF(ISNUMBER(SEARCH("cat",B2)),"cat, ","")&IF(ISNUMBER(SEARCH("dog",B2)),"dog, ","")&IF(ISNUMBER(SEARCH("orange",B2)),"orange, ","")&IF(ISNUMBER(SEARCH("pear",B2)),"pear","")

    I'm still trying to work out the trailing comma issue. Though someone else may come along with a better option.

  7. #7
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: search multiple words in a cell and output what the cell contains

    Try this based on previous Criteria , shown in code variable "Txt".
    Results in column "C".
    Please Login or Register  to view this content.
    Regards Mick

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: search multiple words in a cell and output what the cell contains

    Since you have sample solution in VBA & Formula. Here's another using PowerQuery.

    1. Custom M function. Paste below into blank query in Advanced Editor and name it fnWordList
    Please Login or Register  to view this content.
    2. Load Original into PQ and also List of words that should be extracted.

    3. Right click on Original. Transform -> Lowercase.

    4. Add custom column to Original and invoke fnWordList
    0.JPG

    5. Change data type of [Extracted] to Text. Load to sheet.

    See attached sample.
    Attached Files Attached Files

  9. #9
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: search multiple words in a cell and output what the cell contains

    I can get you rid of the trailing commas with a second step, so if you use mine from post #6, you can use this in another column...
    =IF(RIGHT(C2,2)=", ",LEFT(C2,LEN(C2)-2),C2) assuming you put the formula I gave you in post #6 in cell C2.
    You haven't commented on anything given you since yesterday so we're not sure you gave up or are using someone's suggestion.

  10. #10
    Registered User
    Join Date
    09-05-2019
    Location
    NY, NY
    MS-Off Ver
    16.28
    Posts
    3

    Re: search multiple words in a cell and output what the cell contains

    Thanks, everyone for your input. Sambo kid, i used your previous formula and was able to remove the trailing comma in the exact way you listed above. Truly appreciate it.

+ 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. [SOLVED] Count words in a cell & output number of occurences of each word in adjecent cell.
    By kprasad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-16-2017, 07:28 AM
  2. Search multiple words in a single cell macro
    By ruissu in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-08-2016, 01:33 PM
  3. Search multiple words in a single cell
    By ruissu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2016, 10:40 AM
  4. Search multiple words in a single cell
    By ruissu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2016, 10:38 AM
  5. Search for multiple words in string in a cell without nested IF
    By momtazkalo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-17-2015, 10:41 AM
  6. Replies: 37
    Last Post: 06-10-2014, 04:08 AM
  7. Search a cell for multiple words and return multiple results in one cell
    By samanthat86 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-23-2013, 12:01 PM

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