+ Reply to Thread
Results 1 to 8 of 8

Extracting characters from a string

  1. #1
    Registered User
    Join Date
    12-01-2006
    Posts
    49

    Lightbulb Extracting characters from a string

    Hi there,

    I am trying to extract a number of character from a string. The format of the string is as follows:

    First Name (space) Last Name (space) RR (cost centre number) (space) (date)

    So an example is as follows:

    JOHN CITIZEN RR533 (26.02.07 TO 25.05.07)

    I need to extract all characters before the RR, so basically the first and last name of the person. I would really appreciate if anyone could let me know how to do it.

    I cannot use the left or right function or even the len funtions as the number of characters in the string vary. The number of characters to the right of "RR" are also non consistent unfortunately.

    Any sort of help would be great!

    Cheers!

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Assuming the first cell is A1, you could use:

    =LEFT(A1,SEARCH("RR",A1)-2)

    Actually, the above will give you an incorrect response if the name has RR in it. So instead, use this:

    =LEFT(A1,SEARCH(" ",A1,SEARCH(" ",A1)+1)-1)

    The above will search for the 2nd space, and return everything to the left of the 2nd space.

    HTH

    Jason
    Last edited by jasoncw; 05-29-2007 at 10:34 PM.

  3. #3
    Registered User
    Join Date
    12-01-2006
    Posts
    49
    Thanks Jason that was quick.

    Is there a way I can actually suppress the errors, for example when it returns #value

    Cheers for your help mate! Much appreciated.

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    No problem. And yes, you can suppress the errors by using ISERROR:
    Please Login or Register  to view this content.
    Jason

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    If
    HARRY JONES RR533 (26.02.07 TO 25.05.07)
    is in A1,

    =LEFT(A1,SEARCH(CHAR(7),SUBSTITUTE(A1," ",CHAR(7),2)&CHAR(7))-1)

    will return "HARRY JONES". It will never return an error value.

  6. #6
    Registered User
    Join Date
    12-01-2006
    Posts
    49

    Smile

    Quote Originally Posted by mikerickson
    If
    HARRY JONES RR533 (26.02.07 TO 25.05.07)
    is in A1,

    =LEFT(A1,SEARCH(CHAR(7),SUBSTITUTE(A1," ",CHAR(7),2)&CHAR(7))-1)

    will return "HARRY JONES". It will never return an error value.

    Cheer for that Mick. That works well too. Small ammendment though, if the surname has two words, it doesn't return the correct value. jason this is true for your formula as well. So for example if a person's name was John Von Dutch, it will only return John Von.

    Is it possible to ammend the formula to return any characters before "_RR" (the underscore being the space before the RR)

    Cheers guys!

  7. #7
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Try

    =IF(ISERROR(LEFT(A2,SEARCH(" RR",A2))),"",LEFT(A2,SEARCH(" RR",A2)))


    rylo

  8. #8
    Registered User
    Join Date
    12-01-2006
    Posts
    49
    Quote Originally Posted by rylo
    Hi

    Try

    =IF(ISERROR(LEFT(A2,SEARCH(" RR",A2))),"",LEFT(A2,SEARCH(" RR",A2)))


    rylo
    Thanks heaps RYLO. Just an addition, I needed to have -1 after the last string in the formula to get rid of the space. Otherwise that formula was perfect.

    Thanks heaps!!!

+ 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