+ Reply to Thread
Results 1 to 12 of 12

If a cell contains a specific text than return a value

  1. #1
    Registered User
    Join Date
    05-31-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    30

    Unhappy If a cell contains a specific text than return a value

    Everywhere I search I see this formula for looking in a column and if a row contains a specific value then to return x, if not return y.
    =IF(ISNUMBER(SEARCH("text", A1)),"X","Y")

    But when I use this in Excel 2010 I get an error. I modify it to look like this... =IF(ISNUMBER(SEARCH("text", A1,,0)),"X","Y")

    It then just returns "X" in every row for my new column.

    What am I doing wrong?

    Thanks,

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: If a cell contains a specific text than return a value

    HI dcdeez,


    You need to search in a cell or in entire column ?
    If you need to search in a cell, then your above formula (without modification) is working perfectly. If a1 has "text" then formula will output result as X.



    Regards,
    DILIPandey
    <click on below * if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), dilipandey@gmail.com

  3. #3
    Registered User
    Join Date
    05-31-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: If a cell contains a specific text than return a value

    Ah I'm sorry. I need it do the entire [A] column. but if I used [A] instead of A1 it does the same thing.

    =IF(ISNUMBER(SEARCH("text", [A],,0)),"X","Y")

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

    Re: If a cell contains a specific text than return a value

    So you want to return an "X" if any of the entries in that column contains "text"? You can adapt it slightly to this array formula (confirm with CTRL+SHIFT+ENTER, not just ENTER):

    =IF(SUM(--ISNUMBER(SEARCH("text",A1:A1000)))>0,"X","Y")

    Obviously amend the range as required.

    Regards
    Click * below if this answer helped

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

  5. #5
    Registered User
    Join Date
    05-31-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: If a cell contains a specific text than return a value

    Quote Originally Posted by XOR LX View Post
    So you want to return an "X" if any of the entries in that column contains "text"? You can adapt it slightly to this array formula (confirm with CTRL+SHIFT+ENTER, not just ENTER):

    =IF(SUM(--ISNUMBER(SEARCH("text",A1:A1000)))>0,"X","Y")

    Obviously amend the range as required.

    Regards
    I want it to search for "text" specifically. Not any text.
    The column it is searching is the description column and if that column has any rows that have the word "text" in it then I want it to return a "Y".

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

    Re: If a cell contains a specific text than return a value

    Did you try the formula I posted? That will search for the string "text", not any text.

    Also, your original post states "if a row contains a specific value then to return x, if not return y", which contradicts what you have just now said - you can obviously work out which part of the the formula to change, I presume?

  7. #7
    Registered User
    Join Date
    05-31-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: If a cell contains a specific text than return a value

    Yes. Your formula returned "The formula contains an invalid character sequence '-'."

    If I change it to =IF(SUM(ISNUMBER(SEARCH("text",A1:A1000)))>0,"X","Y") then it returns "Operator or expression ':' is not supported in this context"

    If I change it to =IF(SUM(ISNUMBER(SEARCH("text",[A])))>0,"X","Y") then it returns "The SUM function only accepts a column reference as an argument."

  8. #8
    Registered User
    Join Date
    05-31-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: If a cell contains a specific text than return a value

    Quote Originally Posted by XOR LX View Post
    Did you try the formula I posted? That will search for the string "text", not any text.

    Also, your original post states "if a row contains a specific value then to return x, if not return y", which contradicts what you have just now said - you can obviously work out which part of the the formula to change, I presume?
    Yes. Your formula returned "The formula contains an invalid character sequence '-'."

    If I change it to =IF(SUM(ISNUMBER(SEARCH("text",A1:A1000)))>0,"X","Y") then it returns "Operator or expression ':' is not supported in this context"

    If I change it to =IF(SUM(ISNUMBER(SEARCH("text",[A])))>0,"X","Y") then it returns "The SUM function only accepts a column reference as an argument."

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

    Re: If a cell contains a specific text than return a value

    What are you using? PowerPivot? This sounds like DAX Syntax error or something?

  10. #10
    Registered User
    Join Date
    05-31-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: If a cell contains a specific text than return a value

    Quote Originally Posted by XOR LX View Post
    What are you using? PowerPivot?
    Probably would have been better if I mentioned that originally... But yes this is in a PowerPivot Window. Is this not possible then?

  11. #11
    Registered User
    Join Date
    05-31-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: If a cell contains a specific text than return a value

    I actually just solved it.
    = IF(SEARCH("text",[A],,0),"X","Y")


    Thanks for your help.

  12. #12
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: If a cell contains a specific text than return a value

    Great

    Please mark this thread as [SOLVED].. thanks.


    Regards,
    DILIPandey
    <click on below * if this helps>

+ 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