+ Reply to Thread
Results 1 to 10 of 10

Formula to put '1' in cell if adjacent cell contains 'XY' text

Hybrid View

  1. #1
    Registered User
    Join Date
    02-06-2011
    Location
    Illinois
    MS-Off Ver
    Excel 2003
    Posts
    13

    Formula to put '1' in cell if adjacent cell contains 'XY' text

    I have a column of cells containing text (column A), and I want to find a formula for the adjacent column (column B) that will put a 1 in column B if the adjacent cell in column A contains "XY".
    I found this formula to count cells with specific text in them: =SUM(LEN(range)-LEN(SUBSTITUTE(range,"text","")))/LEN("text")
    But I'm not sure how to do what I want.
    Advice much appreciated!
    Last edited by heathercoldsmith; 02-07-2011 at 09:13 AM.

  2. #2
    Registered User
    Join Date
    02-06-2011
    Location
    Illinois
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Formula to put '1' in cell if adjacent cell contains 'XY' text

    Got it: =IF(ISERROR(SEARCH("*Text*",G2,1)),"0","1 ")

  3. #3
    Registered User
    Join Date
    02-06-2011
    Location
    Illinois
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Formula to put '1' in cell if adjacent cell contains 'XY' text

    Okay, now what if I only want to count the cell if the text I'm interested in, "XY" stands alone rather than as part of a word?

  4. #4
    Registered User
    Join Date
    02-06-2011
    Location
    Illinois
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Formula to put '1' in cell if adjacent cell contains 'XY' text

    Thanks, Robert. Another question...

    Quote Originally Posted by heathercoldsmith View Post
    Okay, now what if I only want to count the cell if the text I'm interested in, "XY" stands alone rather than as part of a word?
    I tried =IF(A2="XY",1,0), but that only works if "XY" is the only thing in the cell. I want to have a "1" in the adjacent column if the cell contains "XY" in the sentence. So if the cell contains "xy said blah blah" the adjacent column would have a 1, but if the cell said "roxy said blay blah" then the adjacent column would have a 0 because XY does not stand alone in the cell.

    Thanks again!
    Heather

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Formula to put '1' in cell if adjacent cell contains 'XY' text

    Hi there,

    You can use =IF(A2="XY",1,0) in whatever cell you want and then fill (copy) it down as required and then sum the range or just =COUNTIF(A2:A10,"XY") for the entire range (change the range to suit).

    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Formula to put '1' in cell if adjacent cell contains 'XY' text

    Try this:

    =IF(LEFT(A2,3)= "xy ",1,IF(ISERROR(SEARCH(" xy ",A2)),0,1))

    HTH

    Robert

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Formula to put '1' in cell if adjacent cell contains 'XY' text

    Or perhaps:

    =ISNUMBER(SEARCH(" xy "," "&A1&" "))+0

  8. #8
    Registered User
    Join Date
    02-06-2011
    Location
    Illinois
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Formula to put '1' in cell if adjacent cell contains 'XY' text

    I tried Robert's formula, but I think I may have replaced text incorrectly and it didn't work. I went with the second one because it was simpler - works like a charm.
    Thank you both!!
    Heather

  9. #9
    Registered User
    Join Date
    06-25-2015
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Formula to put '1' in cell if adjacent cell contains 'XY' text

    --deleted--- new post created apologies
    Last edited by martinlompa; 06-25-2015 at 02:44 AM.

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Formula to put '1' in cell if adjacent cell contains 'XY' text

    Hi.

    It's a forum rule that you start your own thread, rather than try to "hijack" someone else's thread. This helps prevent massive confusion arising -which will happen if it is not clear which question is being answered. So please start your own thread and explain your own problem (make sure that, right from the start, you use a meaningful title (NOT things like "help needed" or "urgent problem"... think of the Google search terms that you would use to find the solution). Also, preferably attach an Excel sheet. Make sure there is enough data to demonstrate your need. Make sure your desired results are shown, mock them up manually if necessary. Remember to remove ALL confidential information first!!!

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    The paperclip icon
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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