+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: find the third space after an ampersand in cell

  1. #1
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    find the third space after an ampersand in cell

    Hey all,

    I have this:
    KNUD J & MARIA L HOSTRUP
    if no comma before first ampersand, then that means last name is at end of cell, so we take content after third space after the ampersand and place it in front and then place a comma and then take content after ampersand and put directly after comma:
    HOSTRUP,MARIA L
    And then in next column, we do above but instead this time we take content before ampersand and stick it after comma:
    HOSTRUP,KNUD J
    I'm stuck trying to figure out how to get content after third space after ampersand:
    =IF(ISERROR(FIND(",",LEFT(A36,FIND("&",A36)-1),1)),CONCATENATE
    
    ,FALSE)
    Thanks for response.

  2. #2
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,300

    Re: finding the third space after an ampersand in cell

    Hi John,

    If KNUD J & MARIA L HOSTRUP is in A1 then
    =FIND(" ",A1,FIND(" ",A1,FIND(" ",A1)+1)+1)
    returns location of third space.

    hth.
    One test is worth a thousand opinions.
    Click the * below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: finding the third space after an ampersand in cell

    Yeah but that's not third space after an ampersand. That's third space in cell. How do I find third space after ampersand so I can extract the last name?

  4. #4
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: finding the third space after an ampersand in cell

    While this formula pulls the last occurrence:
    =RIGHT(A36,LEN(A36)-SEARCH("@",SUBSTITUTE(A36," ","@",LEN(A36)-LEN(SUBSTITUTE(A36," ","")))))
    I am trying to pull everything after three spaces after ampersand. because the last name might be multiple words.

  5. #5
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,006

    Re: finding the third space after an ampersand in cell

    Do these work for you?
    =IF(FIND(",",B2&",")<FIND("&",B2&"&"),TRUE,RIGHT(B2,LEN(B2)-SEARCH("@",SUBSTITUTE(B2," ","@",LEN(B2)-LEN(SUBSTITUTE(B2," ","")))))&", "&LEFT(B2,FIND("&",B2&"&")-1))
    =IF(FIND(",",B2&",")<FIND("&",B2&"&"),TRUE,RIGHT(B2,LEN(B2)-SEARCH("@",SUBSTITUTE(B2," ","@",LEN(B2)-LEN(SUBSTITUTE(B2," ","")))))&", "&SUBSTITUTE(RIGHT(B2,LEN(B2)-FIND("&",B2&"&")-1),RIGHT(B2,LEN(B2)-SEARCH("@",SUBSTITUTE(B2," ","@",LEN(B2)-LEN(SUBSTITUTE(B2," ",""))))),""))
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  6. #6
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,006

    Re: finding the third space after an ampersand in cell

    Taking an assumption of 2 cases from your question :-


    KNUD J & MARIA L HOSTRUP
    HOSTRUP, KNUD J & MARIA L

    =IF(FIND(",",B3&",")<FIND("&",B3&"&"),LEFT(B3,FIND(",",B3&",")-1)&", "&TRIM(SUBSTITUTE(SUBSTITUTE(B3,LEFT(B3,FIND(",",B3&",")),""),RIGHT(B3,LEN(B3)-FIND("&",B3&"&")+1),"")),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ","")))))&", "&LEFT(B3,FIND("&",B3&"&")-1))
    =IF(FIND(",",B3&",")<FIND("&",B3&"&"),LEFT(B3,FIND(",",B3&",")-1)&","&RIGHT(B3,LEN(B3)-FIND("&",B3&"&")),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ","")))))&", "&SUBSTITUTE(RIGHT(B3,LEN(B3)-FIND("&",B3&"&")-1),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))),""))
    Will return
    HOSTRUP, KNUD J
    HOSTRUP, MARIA L

    Given Either Case!
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  7. #7
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: finding the third space after an ampersand in cell

    Thanks for response.

    It almost works.

    In cases, where there's no ampersand and comma, I would like it just to return length of cell:
    Sarah Ann Little Junior
    would just return
    Sarah Ann Little Junior
    since there's no ampersand and comma.

    Your solution turns it into this:
    Junior,Sarah Ann Little

    Thanks for response.

  8. #8
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: finding the third space after an ampersand in cell

    I'm thinking of sticking a condition like this:
    =IF(AND(A20<>",",A20<>"&"),TRUE,FALSE)

    before your recommended condition

    Problem is the formula I have above doesn't work as expected. I'm trying to say if the cell does not contain a comma and ampersand then just return length of cell, otherwise run your condition.
    Last edited by johnmerlino; 11-09-2010 at 10:52 PM.

  9. #9
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,006

    Re: finding the third space after an ampersand in cell

    your conditions are looking for the cell to contain just "&" or "," :-

    =IF(FIND(",",B4&",")=FIND("&",B4&"&"),TRUE,FALSE)

    This avoids a not found error,and can only be true if the string contains neither a , or a &

    combining these :-

    =IF(FIND(",",B4&",")=FIND("&",B4&"&"),B4,IF(FIND(",",B4&",")<FIND("&",B4&"&"),LEFT(B4,FIND(",",B4&",")-1)&", "&TRIM(SUBSTITUTE(SUBSTITUTE(B4,LEFT(B4,FIND(",",B4&",")),""),RIGHT(B4,LEN(B4)-FIND("&",B4&"&")+1),"")),RIGHT(B4,LEN(B4)-SEARCH("@",SUBSTITUTE(B4," ","@",LEN(B4)-LEN(SUBSTITUTE(B4," ","")))))&", "&LEFT(B4,FIND("&",B4&"&")-1)))
    =IF(FIND(",",B4&",")=FIND("&",B4&"&"),"",IF(FIND(",",B4&",")<FIND("&",B4&"&"),LEFT(B4,FIND(",",B4&",")-1)&","&RIGHT(B4,LEN(B4)-FIND("&",B4&"&")),RIGHT(B4,LEN(B4)-SEARCH("@",SUBSTITUTE(B4," ","@",LEN(B4)-LEN(SUBSTITUTE(B4," ","")))))&", "&SUBSTITUTE(RIGHT(B4,LEN(B4)-FIND("&",B4&"&")-1),RIGHT(B4,LEN(B4)-SEARCH("@",SUBSTITUTE(B4," ","@",LEN(B4)-LEN(SUBSTITUTE(B4," ",""))))),"")))
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  10. #10
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: finding the third space after an ampersand in cell

    This might work:
    =IF(AND(ISERROR(FIND(",",A20)),ISERROR(FIND("&",A20))),TRUE,FALSE)

  11. #11
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,006

    Re: finding the third space after an ampersand in cell

    As an alternative a 3 way IF :-

    =CHOOSE(SIGN((FIND(",",B2&",")-FIND("&",B2&"&")))+2,1,2,3)

    giving :-

    =CHOOSE(SIGN((FIND(",",B2&",")-FIND("&",B2&"&")))+2,LEFT(B2,FIND(",",B2&",")-1)&", "&TRIM(SUBSTITUTE(SUBSTITUTE(B2,LEFT(B2,FIND(",",B2&",")),""),RIGHT(B2,LEN(B2)-FIND("&",B2&"&")+1),"")),B2,RIGHT(B2,LEN(B2)-SEARCH("@",SUBSTITUTE(B2," ","@",LEN(B2)-LEN(SUBSTITUTE(B2," ","")))))&", "&LEFT(B2,FIND("&",B2&"&")-1))
    And

    CHOOSE(SIGN((FIND(",",B2&",")-FIND("&",B2&"&")))+2,LEFT(B2,FIND(",",B2&",")-1)&","&RIGHT(B2,LEN(B2)-FIND("&",B2&"&")),"",RIGHT(B2,LEN(B2)-SEARCH("@",SUBSTITUTE(B2," ","@",LEN(B2)-LEN(SUBSTITUTE(B2," ","")))))&", "&SUBSTITUTE(RIGHT(B2,LEN(B2)-FIND("&",B2&"&")-1),RIGHT(B2,LEN(B2)-SEARCH("@",SUBSTITUTE(B2," ","@",LEN(B2)-LEN(SUBSTITUTE(B2," ",""))))),""))
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  12. #12
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: finding the third space after an ampersand in cell

    Thanks for the replies.

    Your excel formulas are too complicated for me to understand. You mention that this:
    =IF(FIND(",",B3&",")<FIND("&",B3&"&"),LEFT(B3,FIND(",",B3&",")-1)&","&RIGHT(B3,LEN(B3)-FIND("&",B3&"&")),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ","")))))&", "&SUBSTITUTE(RIGHT(B3,LEN(B3)-FIND("&",B3&"&")-1),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))),""))
    will return this:
    HOSTRUP, MARIA L

    I'm looking to do:
    =IF(ISERR(FIND("&",A1,1)),"",IF(AND(ISERROR(FIND(",",A1)),IF(ISNUMBER(FIND("&",A1)))),RUN YOUR CODE,LEFT(A1,FIND("&",A1,1)-1)))

    So basically if it doesn't find an ampersand, return blank cell. If it doesn't find comma but finds ampersand, run your code. Otherwise if there's an ampersand and a comma, then run: LEFT(A1,FIND("&",A1,1)-1)))

    I just can't get your code integrating into the above formula, because it's too complicated for me to understand where it begins and ends in regards to how I intend it to work above.

    Thanks for response.

  13. #13
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,006

    Re: finding the third space after an ampersand in cell

    The problem is you keep asking parts of the overall problem, then adding more problems to it!

    The easiest way is to provide a list of all possible cases you have, rather than try to solve each one individually and combine the results, you are quickly going to come up to the nesting limit!

    Otherwise you are just going to keep posting more situations!
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  14. #14
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: finding the third space after an ampersand in cell

    Once I fill in "Run your code" with the formula that returns like in your example "HOSTRUP,MARIA L"
    then that would be it.

    This is the only situations that could be:
    =IF(ISERR(FIND("&",A1,1)),"",IF(AND(ISERROR(FIND(",",A1)),IF(ISNUMBER(FIND("&",A1)))),RUN YOUR CODE,LEFT(A1,FIND("&",A1,1)-1)))

    If no ampersand, return empty cell, as shown above, if no comma but ampersand exists, then run your code, as shown above, otherwise that must mean that must mean that there is no ampersand but there is a comma so we just return LEFT(A1,FIND("&",A1,1)-1).
    And that would be it.

    In other words, all i really need is a formula to grab, for example, "HOSTRUP,MARIA L" right in the spot where i say "run your code".
    Last edited by johnmerlino; 11-10-2010 at 12:28 AM.

  15. #15
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: find the third space after an ampersand in cell

    Trying to extract the portion that I need:

    =LEFT(B3,FIND(",",B3&",")-1)&","&RIGHT(B3,LEN(B3)-FIND("&",B3&"&")),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))&", "&SUBSTITUTE(RIGHT(B3,LEN(B3)-FIND("&",B3&"&")-1),RIGHT(B3,LEN(B3)-SEARCH("@",SUBSTITUTE(B3," ","@",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))),""))
    This tells me "The Formula You Typed Contains Errors" but it doesn't highlight anything in particular.

+ 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.2.0