+ Reply to Thread
Results 1 to 38 of 38

Search For multiple words in a cell if a certain word matches produce a certain value

  1. #1
    Registered User
    Join Date
    06-09-2014
    Location
    Phoenix
    MS-Off Ver
    2010
    Posts
    11

    Search For multiple words in a cell if a certain word matches produce a certain value

    So I have a cell with multiple words in A1. I want to check for the word "red" in A1 and if red exists return a value of "red" in B2, IF "red" is not found then search for "blue", if "blue" exists return a value of "blue" in B2, if "blue" is not found is not found then search for "green", if "green" exists then return "green" in B2, if none exist then return value of "none"

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Create a list of your keywords in say G1:G3

    =IFERROR(LOOKUP(2^15,SEARCH(G1:G3,A1),G1:G3),"none")

    G1 = red
    G2 = blue
    G3 = green


    Hope that helps.

  3. #3
    Registered User
    Join Date
    06-09-2014
    Location
    Phoenix
    MS-Off Ver
    2010
    Posts
    11

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Let me rephrase the problem

    I have a cell with multiple words in A1. I want to check for the word "red" in A1 and if red exists return a value of "red XL" in B2, IF "red" is not found then search for "blue", if "blue" exists return a value of "blue Medium" in B2, if "blue" is not found is not found then search for "green", if "green" exists then return "Big Green in the house" in B2, if none exist then return value of "none"

    The values returned won't be identical to the values searched for.

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    With
    A1: some text...My red apple looks a little green

    E1:E3 containing this list:
    Red
    Blue
    Green

    This regular formula returns the first matching value from A1...if no matches, then: None
    Please Login or Register  to view this content.
    In the above example, that formula returns: Red

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  5. #5
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Allow me to rephrase the answer...

    put your list of keywords in say G1:G3
    And put your list of results for each keyowrd in H1:H3
    G1 = Red, H1 = red XL
    G2 = Blue, H2 = blue Medium
    G3 = Green, H3 = Big Green

    =IFERROR(LOOKUP(2^15,SEARCH(G1:G3,A1),H1:H3),"none")

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Try this:
    E1:F3 contains this list:
    Please Login or Register  to view this content.
    This regular formula returns the phrase associated with the first matching color in A1
    Please Login or Register  to view this content.
    Is that something you can work with?

  7. #7
    Registered User
    Join Date
    06-09-2014
    Location
    Phoenix
    MS-Off Ver
    2010
    Posts
    11

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Ah very nice ok, I get it so I should create some lists lol. For organizational reasons I will put the lists on different worksheet now how does that fit in to this equation if they are on a different worksheet?

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    You can add sheet references to the formula

    =IFERROR(LOOKUP(2^15,SEARCH('sheet with list'!G1:G3,A1),'sheet with list'!H1:H3),"none")


    A couple notes.
    1 there cannot be any blanks in G1:G3

    2 if A1 has 2 or more of the key words, the formula returns the one that appears last (furthest down) in the list.

    So with Ron's text string
    My red apple looks a little green

    If you want to return Red XL and not Big Green, then Red should be in G3 instead of G1

    3 and finally, it is NOT case sensitive.
    if G1 = red, then it will consider RED a match.
    To make it case sensitive, change search to FIND.
    Last edited by Jonmo1; 06-09-2014 at 01:10 PM.

  9. #9
    Registered User
    Join Date
    06-09-2014
    Location
    Phoenix
    MS-Off Ver
    2010
    Posts
    11

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Ok awesome thanks a million I will give it a shot.

  10. #10
    Registered User
    Join Date
    05-16-2014
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    great solution. Just had quick question, what does 2^15 do here?

  11. #11
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    The maximum possible number of characters in a cell in Excel 2010 is 32767. Hence, this is also the maximum possible return for the SEARCH function. Since 2^15=32768, this ensures that the LOOKUP formula will always return the last possible match.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  12. #12
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    2^15 is 2 to the power of 15 = 32768
    That just happens to be 1 larger than the maximum lenth text string a cell can hold.
    So it assures the lookup value is larger than any possible result of Search.

  13. #13
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Quote Originally Posted by XOR LX View Post
    The maximum possible number of characters in a cell in Excel 2010 is 32767. Hence, this is also the maximum possible return for the SEARCH function. Since 2^15=32768, this ensures that the LOOKUP formula will always return the last possible match.

    Regards
    But, but, but, you have to use BigNum.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  14. #14
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Quote Originally Posted by Tony Valko View Post
    But, but, but, you have to use BigNum.
    Why is that?

  15. #15
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Quote Originally Posted by Jonmo1 View Post
    Why is that?
    I've always wondered why myself. Ask the people that always use it.

  16. #16
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Quote Originally Posted by Tony Valko View Post
    I've always wondered why myself. Ask the people that always use it.
    You did just use it (or at least imply that it should be used), So I'm asking you.
    Quote Originally Posted by Tony Valko View Post
    But, but, but, you have to use BigNum.

  17. #17
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Quote Originally Posted by Jonmo1 View Post
    You did just say it, I'm asking you.
    And you got my answer.

  18. #18
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Some people just like to use named constants.
    Others use them strategically.
    Yet, others don't use them at all.

  19. #19
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    I guess I fall into that 3rd category (mostly).

    If I know the nature of the data I'll use the smallest "BigNum" that will work.

  20. #20
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Yeah, unless the constant will be used in various places in the workbook...or if it's a rate that I want to clearly identify (Tax_Rate)...I just embed the constant in the formula. So, I'm probably a "use them strategically...but, sparingly" type. :\

  21. #21
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    This is the key for me.
    Quote Originally Posted by Tony Valko View Post
    If I know the nature of the data
    From the point of view as a helper on this forum, it's not possible for me to 'know' the nature of the data.
    Thefore I take the position of being absolutely certain regardless of the nature of the data.


    To answer your question Why no BigNum in this formula..
    2^15 (as you said) is the smallest BigNum that I know will work.
    Because we do 'know' with aboslute certainty that Search/Find can't possibly return a number equal or larger than 2^15

    In other formulas, such as finding the last number in a column, we (as in helpers on this forum) can't possibly know with absolute certainty, so I choose Bignum.

  22. #22
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Quote Originally Posted by Jonmo1 View Post
    it's not possible for me to 'know' the nature of the data.
    Sure it is.

    Sometimes OP's will actually give us the real info we need.

    I have a column of dates. I'd like a formula to return the last date in the column.
    Date gives us enough info to know the nature of the data.

  23. #23
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Quote Originally Posted by Tony Valko View Post
    Sometimes OP's will actually give us the real info we need.
    And the OP is never wrong (or mistaken to be fair)...right?

    Quickly....without googling or using Excel...
    What is the last date (furthest in the future) that Excel can use?
    And what is the corresponding serial # that you would put in a lookup formula?

  24. #24
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    BigNumber is too much typing for me. :|
    I typically use either:
    10^10 which is 10 billion.
    or
    10^99 (which I don't think has a name)

  25. #25
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Here's bignum
    9.99999999999999E+307

  26. #26
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Largest year 9999. And I didn't (have to) look!

  27. #27
    Registered User
    Join Date
    06-09-2014
    Location
    Phoenix
    MS-Off Ver
    2010
    Posts
    11

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Ok sorry got caught up in meetings. I need it so the values don't change on the list worksheet.

    =IFERROR(LOOKUP(2^15,SEARCH('sheet with list'!G1:G3,A1),'sheet with list'!H1:H3),"none")

    so when I drag the formula down the spread sheet it doesn't do this =IFERROR(LOOKUP(2^15,SEARCH('sheet with list'!G2:G4,A2),'sheet with list'!H2:H),"none")

  28. #28
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Maybe this:

    =IFERROR(LOOKUP(35000,SEARCH('sheet with list'!G$1:G$3,A1),'sheet with list'!H$1:H$3),"none")

    In this case I use 35000 as the lookup value.

    It's greater than the max number of characters allowed in a cell, 32767, and it's a constant (doesn't need to be calculated).

  29. #29
    Registered User
    Join Date
    06-09-2014
    Location
    Phoenix
    MS-Off Ver
    2010
    Posts
    11

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Quote Originally Posted by Jonmo1 View Post
    You can add sheet references to the formula

    =IFERROR(LOOKUP(2^15,SEARCH('sheet with list'!G1:G3,A1),'sheet with list'!H1:H3),"none")




    A couple notes.
    1 there cannot be any blanks in G1:G3

    2 if A1 has 2 or more of the key words, the formula returns the one that appears last (furthest down) in the list.

    So with Ron's text string
    My red apple looks a little green

    If you want to return Red XL and not Big Green, then Red should be in G3 instead of G1

    3 and finally, it is NOT case sensitive.
    if G1 = red, then it will consider RED a match.
    To make it case sensitive, change search to FIND.
    It only seems to look for and return the last values on the lists any ideas

  30. #30
    Registered User
    Join Date
    06-09-2014
    Location
    Phoenix
    MS-Off Ver
    2010
    Posts
    11

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    So I have two lists each with two values it appears to only be looking for the 2nd value any thoughts

  31. #31
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Can you post a SMALL sample file and show us what result(s) you expect?

    SMALL = no more than 20 rows worth of data

  32. #32
    Registered User
    Join Date
    06-09-2014
    Location
    Phoenix
    MS-Off Ver
    2010
    Posts
    11

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    I highlighted the columns I want to use this function for.sample.xlsx
    Attached Files Attached Files

  33. #33
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    I don't see any highlighted cells.

    Sorry, but I can't make heads or tails out of your file.
    Last edited by Tony Valko; 06-09-2014 at 08:30 PM.

  34. #34
    Registered User
    Join Date
    06-09-2014
    Location
    Phoenix
    MS-Off Ver
    2010
    Posts
    11

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    I just left my office. I will send a new file in an hour.

  35. #35
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    As I said in post # 8
    Quote Originally Posted by Jonmo1 View Post
    if A1 has 2 or more of the key words, the formula returns the one that appears last (furthest down) in the list.

    So with Ron's text string
    My red apple looks a little green

    If you want to return Red XL and not Big Green, then Red should be in G3 instead of G1
    You have to write your list with the keyword priorities sorted Ascending
    The keywords with the highest priority go last (at the bottom)

    So with your given example of Red Blue and Green
    Quote Originally Posted by Coulbourne View Post
    So I have a cell with multiple words in A1. I want to check for the word "red" in A1 and if red exists return a value of "red" in B2, IF "red" is not found then search for "blue", if "blue" exists return a value of "blue" in B2, if "blue" is not found is not found then search for "green", if "green" exists then return "green" in B2, if none exist then return value of "none"
    .
    With those rules as written,
    G1=Green
    G2=Blue
    G3=Red
    Last edited by Jonmo1; 06-09-2014 at 09:27 PM.

  36. #36
    Registered User
    Join Date
    06-09-2014
    Location
    Phoenix
    MS-Off Ver
    2010
    Posts
    11

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    HelpSheet.xlsx

    So on worksheet "19" Column I has the formula. It is looking for items in list A1 on worksheet "19 Attributes" in column E on worksheet "19". So in row 4 it should return a value but instead is returning the value of "none".

  37. #37
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,366

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    You have extra spaces on 19 attributes that you need to remove them, just add with TRIM:

    IFERROR(LOOKUP(2^15,FIND(TRIM('19 Attributes'!A$2:A$3),E2),'19 Attributes'!B$2:B$3),"none")
    Last edited by azumi; 06-10-2014 at 04:15 AM.

  38. #38
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Search For multiple words in a cell if a certain word matches produce a certain value

    Quote Originally Posted by Tony Valko View Post
    But, but, but, you have to use BigNum.
    xxxxxxxxxxxxxxxx

+ 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. 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
  2. Formula to recognise one word from multiple words in the same cell
    By JLucy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-27-2013, 11:48 AM
  3. Replies: 5
    Last Post: 01-10-2013, 09:51 AM
  4. Search Col.A for words that contain charactrs in Col.B & list all matches adjacently
    By macemegane in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-13-2010, 11:17 AM
  5. [SOLVED] search for a specific word and copy the word and the preceeding words until a comma
    By DHANANJAY in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-31-2005, 09:10 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