+ Reply to Thread
Results 1 to 6 of 6

"CONTAINS" formula?

  1. #1
    Registered User
    Join Date
    03-14-2006
    Posts
    12

    "CONTAINS" formula?

    I'm trying to have a given cell return one of three variables based on whether a range of cells contains any of certain criteria.

    Assume cells B2 through B18 each contain at least one of the following "Bob", "Tom" or "Harry".

    In cell B20, I want to return a value of "Tuesday" if ANY of the B2-B18 cells contain "Bob".

    I want to return a value of "Wednesday" if ANY of the B2-B18 cells contains "Tom" and a value of "Thursday" if ANY of the B2-B18 cells contain "Harry".

    Is there a formula which will do this? Thanks

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Welcome to the forum.

    What do you want the value to be if B2 is "Bob", B3 "Tom" and B4 "Harry"

  3. #3
    Registered User
    Join Date
    03-14-2006
    Posts
    12
    You've made me re-think this a little bit. Thank you.

    Let's simplify this a bit and say:

    In Cell B20, if B2 to B18 contains Bob or Harry or both, return "Tuesday".

    Then I'll repeat the process in cell b21, saying, if B2 to B18 contains Tom or Harry or both, return "Wednesday".

    Does that make sense? Thanks

  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

    "CONTAINS" formula?

    Try something like this:

    Please Login or Register  to view this content.
    Or...do you mean the cells could contain phrases that include names,
    like "Is that Harry, Bob?"

    If that's the case, try this:
    Please Login or Register  to view this content.
    Does that help?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  5. #5
    Registered User
    Join Date
    03-14-2006
    Posts
    12
    We're close with this formula:

    B20: =IF(COUNT(MATCH({"Bob","Harry"},$B$2:$B$18,0)),"Tuesday","")

    The missing piece is if one of the source cells contains Bob as part of a larger phrase, such as "Bobby" or "Bobby-Douglas" I would still want it to return the assigned value of "Tuesday". And the same would be true of "Harry". I'm looking for that arrangement of letters, even if it's attached to something else. So if one of the source cells contained "HarryAlligator", I still would want to it to see that "Harry" was contained within that cell and return a value of "Tuesday".

    Thanks so much for your help!

  6. #6
    Registered User
    Join Date
    03-14-2006
    Posts
    12
    Ooops - It appears that the second formula option you provided does exactly what I just outlined moments ago. I got a little tunnelvision there and missed that second formula. Thanks again.

+ 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