+ Reply to Thread
Results 1 to 5 of 5

Formula to find a number in a string of numbers separated by a symbol

  1. #1
    Registered User
    Join Date
    11-29-2012
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    2

    Formula to find a number in a string of numbers separated by a symbol

    Hello,

    I have column A that has entries looking like:
    cell A1: 1|2|3|4|10|14
    cell A2: 1|9|13
    cell A3: 4
    cell A4: 5|14
    cell A5: 1
    cell A6: 1|11
    etc.

    The numbers in each cell range from 1-14 and they are always in ascending order.

    What I want to do is in Column B, return "yes" if the cell in A has the number 1 and return "no" if it doesn't.

    I've tried using the FIND fxn, but it also counts "11" as a "yes". So I tried to FIND "1|". But this was problematic because cells with only the number "1" will return "no" because there is no "|" bar.

    This gets tricky, because in Column C, I want to return "yes" if the cell in A has the number 2 and return "no" if it doesn't. Again, FIND fxn counts "12" as a "yes".

    I've spent so much time on this problem and still can't figure it out. Your help is very much appreciated!
    Last edited by cslm001; 12-11-2012 at 05:55 PM.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Formula to find a number in a string of numbers separated by a symbol

    If you use Text to Columns with "|" as a separator you can simply use IF(COUNTIF(...)<>0,"yes","no")
    Of course this will reformat your spreadsheet somewhat.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Formula to find a number in a string of numbers separated by a symbol

    Try like this

    =IF(ISNUMBER(FIND("|1|","|"&A1&"|")),"Yes","No")
    Audere est facere

  4. #4
    Registered User
    Join Date
    11-29-2012
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Formula to find a number in a string of numbers separated by a symbol

    Quote Originally Posted by daddylonglegs View Post
    Try like this

    =IF(ISNUMBER(FIND("|1|","|"&A1&"|")),"Yes","No")

    Amazing!!! This is exactly what I needed. Thank you so much. I got a formula working, but it's not as concise as yours:

    =IF(AND(ISERROR(FIND("1",A1))=FALSE,IF(ISERROR(FIND("1",A1))=TRUE,0,FIND("1",A1)) <> IF(ISERROR(FIND("10",A1))=TRUE,0,FIND("10", A1)),IF(ISERROR(FIND("1",A1))=TRUE,0,FIND("1",A1)) <> IF(ISERROR(FIND("11",A1))=TRUE,0,FIND("11", A1)), IF(ISERROR(FIND("1",A1))=TRUE,0,FIND("1",A1)) <> IF(ISERROR(FIND("12",A1))=TRUE,0,FIND("12", A1)), IF(ISERROR(FIND("1",A1))=TRUE,0,FIND("1",A1)) <> IF(ISERROR(FIND("13",A1))=TRUE,0,FIND("13", A1)), IF(ISERROR(FIND("1",A1))=TRUE,0,FIND("1",A1)) <> IF(ISERROR(FIND("14",A1))=TRUE,0,FIND("14", A1))), "YES", "NO")


    Thanks again!

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Formula to find a number in a string of numbers separated by a symbol

    If that takes care of your original query, please select Thread Tools from the menu above and mark the thread as solved. Thanks.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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