Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Las Vegas, Nevada, USA
    Posts
    334
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Finding the Nth occurance of a character in a stri (Excel 2003)

    I have a list of items which contain hyphens to separate Division-Department-JobNumber-JobTitle.
    I would like to parse out the Job Title from each record in the list but I can't figure out how to get FIND to return the location of the third occurrence of the hyphen to use as a starting point for RIGHT.
    I got as far as =RIGHT(F36,LEN(F36)-FIND("-",F36,1)) which strips out the division, but I thought I should see if there's an easier way to accomplish this.

  2. #2
    5 Star Lounger
    Join Date
    Aug 2004
    Location
    Connecticut, USA
    Posts
    816
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding the Nth occurance of a character in a stri (Excel 2003)

    A not so pretty way:
    =MID(A1,FIND("-",A1,FIND("-",A1)+1)+1,99)

    I've seen a better method - I'm looking for it....

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Finding the Nth occurance of a character in a stri (Excel 2003)

    Hi Arcturus16a,

    If the string you want to search is in A1, the substring you want to find is in A2 and the substring instance you want to find is in A3, then the following formula will return the position where the nth occurrence of the substring being searched for starts:
    =FIND("‡",SUBSTITUTE(A1,A2,"‡",A3))
    Similarly, if you want to find the starting position of the 3rd '_':
    =FIND("‡",SUBSTITUTE(A1,"_","‡",3))
    There is nothing particularly special about the use of ASCII 135 (ie ‡), except that it’s unlikely to appear in any 'normal' text string.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Finding the Nth occurance of a character in a stri (Excel 2003)

    You could also use Text to Columns using the hyphen as the delimiter to quickly break the data out into 4 columns, if that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    2 Star Lounger
    Join Date
    Aug 2004
    Posts
    123
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Finding the Nth occurance of a character in a

    F36 : Division-Department-JobNumber-JobTitle

    Formula to parse out the JobTitle :

    1] =RIGHT(F36,LEN(F36)-FIND("‡",SUBSTITUTE(F36,"-","‡",3)))

    or

    2] =TRIM(RIGHT(SUBSTITUTE(F36,"-",REPT(" ",50)),50))

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Las Vegas, Nevada, USA
    Posts
    334
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Finding the Nth occurance of a character in a

    Amazing! Well, "Amazing!" to me anyway, probably not to you . All these solutions work very well.
    MBARRON's solution =MID(A1,FIND("-",A1,FIND("-",A1)+1)+1,99) parses out the Div-Dept leaving the Job Code and Job Title
    MACROPOD's =FIND("‡",SUBSTITUTE(A1,"-","‡",3)) tells me the exact position of the Nth (3rd) hyphen
    RORY I didn't want to use the Text to Columns because of the extra steps required. But since I'm showing this file to a trainee I wont forget to demonstrate it's use.
    BOSCO_YIP'S solutions produced different results in my list. The second solution found records where our HR department had added a hyphen to designate "- FT" and "- PT" (Full/Part time employees). But it was the first solution that did the whole job for me (for some reason I needed to TRIM those results. Extra space in one of the records).

    Thanks to you all for your help. I'll be sure to share this lesson here at work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •