+ Reply to Thread
Results 1 to 8 of 8

Look for multiple strings in a cell

  1. #1
    Registered User
    Join Date
    03-06-2012
    Location
    seattle, USA
    MS-Off Ver
    Excel 2010
    Posts
    41

    Look for multiple strings in a cell

    Hi,

    I would like to check if any of 'n' strings in a cell and return "found" if any of the 'n' strings is found in the cell.

    Example:

    A1 contains - "MAYURI FOODS AND VIDEO REDMOND WA"

    A2 should display "found" if A1 contains one of the values "FOOD, APNA, UDUPI"

    I tried =IF(COUNTIF(B167,{"*MAYURI*","*APNA*","*UDUPI*"}),"found") . But it did not work.

    Can any one give me a solution to my requirement?

    Thanks in advance.
    Last edited by reddy14; 03-06-2012 at 05:30 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Look for multiple strings in a cell

    Try:

    =IF(SUM(COUNTIF(B167,{"*MAYURI*","*APNA*","*UDUPI*"})),"found","")
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    03-06-2012
    Location
    seattle, USA
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Look for multiple strings in a cell

    THANKS A LOT NBVC for your quick reply. It worked.

    When I use the formula =COUNTIF(B167,{"*MAYURI*","*APNA*","*UDUPI*"})m it is giving me 1 if B167 has "MAYURI FOODS AND VIDEO REDMOND WA"
    and it is returning 0 if B167 has "UDUPI CAFE BELLEVUE WA"

    Could yo please tell me why it is returning zero in the second case?

    Also, could you tell me the reason for using SUM() in the formula?

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Look for multiple strings in a cell

    Select the cell with your original formula and the go to the Formula tab, and then click Evaluate Formula in the Formula Auditing section. Click the Evaluate formula and you will see that it actually only looks at the first string *MAYURI*". So it counted 1 when Mayuri was within the string.

    Now try again with the COUNTIF() wrapped in a SUM()

    =SUM(COUNTIF(B167,{"*MAYURI*","*APNA*","*UDUPI*"}))

    you will see now, it evaluates each of the values withing the criteria string, then it sums the values... so any sum over 0 is considered "TRUE" for your IF statement.

  5. #5
    Registered User
    Join Date
    03-06-2012
    Location
    seattle, USA
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Look for multiple strings in a cell

    Thanks again for detailed explanation. I will keep in mind the tip "evaluate formula" which is very helpful.

    I understand that =COUNTIF(B167,{"*MAYURI*","*APNA*","*UDUPI*"}) is equal to =COUNTIF(B167,{"*MAYURI*"})

    Now, another question raised in my mind. I would like to know the answer for it to improve my knowledge though it is not in my current requirements.

    Question is, "Which function should be used to check if ALL the 3 values(Mayuri, UDUPI, APNA) are part of B167?"

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Look for multiple strings in a cell

    If your looking for a 1/0 answer if all three are found, then:

    =--AND(COUNTIF(I1,"*MAYURI*"),COUNTIF(I1,"*APNA*"),COUNTIF(I1,"*UDUPI*"))

    if you use SUM, it could falsely tell you 3, but it could be that one of the words are duplicated and one of them doesn't exist in the string.

    in an IF, you would use

    =IF(AND(COUNTIF(I1,"*MAYURI*"),COUNTIF(I1,"*APNA*"),COUNTIF(I1,"*UDUPI*")),"Found","")

  7. #7
    Registered User
    Join Date
    03-06-2012
    Location
    seattle, USA
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Look for multiple strings in a cell

    Thank you.

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Look for multiple strings in a cell

    You are welcome.

+ 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