+ Reply to Thread
Results 1 to 7 of 7

UDF for finding text in cell from a list of text

  1. #1
    Forum Contributor
    Join Date
    01-25-2011
    Location
    Virginia
    MS-Off Ver
    Excel 2016
    Posts
    166

    UDF for finding text in cell from a list of text

    I need a UDF to determine if a cell has any of several words from a list and return one phrase if true and another if false

    Example:
    A1: The big red apple tree
    A2: The big apple tree

    B1: Color
    B2:Blue
    B3:Red
    B4: Yellow
    etc.

    so for A1 it would look for any of the words in column B and return "COLOR" since Red is in A1 and in column b

    For A2 it would return "NO COLOR", since none of the words in column B are in the string in A2.

    Thanks in advance,

    Tom
    Last edited by tom.hogan; 01-26-2011 at 09:36 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: UDF for finding text in cell from a list of text

    Hello Tom,

    Welcome to the Forum!

    This UDF will return "Color" or "No Color" based on the entries in the named range "Colors".
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    01-25-2011
    Location
    Virginia
    MS-Off Ver
    Excel 2016
    Posts
    166

    Re: UDF for finding text in cell from a list of text

    Leith,
    Awesome, thanks for the quick reply, it works perfectly!

    One more question, how would you make this more generic, i.e. allow entries into the formula for the range and the responses. Say we call the formula ISWORD() with the following entries: search cell, range of desired words, response if true, response if false

    Thanks again,

    Tom

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: UDF for finding text in cell from a list of text

    Hello Tom,

    Here is the updated macro. If you don't specify a true/false response then the macro returns True or False.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-25-2011
    Location
    Virginia
    MS-Off Ver
    Excel 2016
    Posts
    166

    Re: UDF for finding text in cell from a list of text

    Leith,
    Again awesome, it works great! Now if i could trouble you one last time. Is it possilbe to have a varible response if true based on a second column in the range? Let's call this one IFTEXT() with the following entries: search cell, range of desired words, column to look in if true (usually 2), response if false

    Example
    Range
    Red Color
    Tree Plant
    Dog Animal

    The big red house - would return "Color"
    The tall tree - would return "Plant"
    The large hairy green dog - would return "Animal"
    The fast car - would return "response if false"

    I know that a string with more than one of the words in the 1st column of the range would cause issues, but I can deal with that via naming conventions.

    Thanx,

    Tom

    P.S. I don't see the scales or the "solved" icons, I want to be sure you get credit for your great answers, can you explain where I find them?

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: UDF for finding text in cell from a list of text

    Hello Tom,

    The scales are on the post menu bar (the top of each post). See the attached picture for what it looks like.

    Here is how to mark a post as "solved":

    How to mark a thread Solved
    1. Go to the first post
    2. Click Edit
    3. Click Go Advanced
    4. Just below the word Title you will see a dropdown with the word No PrefIx.
    5. Change to Solved
    6. Click Save

    As for this next macro, you are basically doing a VLookup within an If statement. This can be accomplished using formulas.

  7. #7
    Forum Contributor
    Join Date
    01-25-2011
    Location
    Virginia
    MS-Off Ver
    Excel 2016
    Posts
    166

    Re: UDF for finding text in cell from a list of text

    Leith,
    VLookup is where i started. But it cannont parse a string, that is why I went down the UDF route. I was able to parse the string using text commands and put the separate words in multiple columns then do multiple vlookups (one per column) to get to my endresult, but it takes a lof of space and calc steps, thus my request for the above UDF. What i need is a VLOOKUP that can look in a string of text for a single word.

    Anyway, thanks for all the help.

    Regards,

    Tom

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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