+ Reply to Thread
Results 1 to 17 of 17

Returning text after the 2nd occurence of a particular character in string

  1. #1
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    79

    Question Returning text after the 2nd occurence of a particular character in string

    Hi All,

    I'm sure this has probably been done to death but for the life of me I cannot find a solution that fits my need.

    I wish to return the characters after the 2nd "_" in a text string. However, this text string may or may not contain further "_" after the text that I want. For instance, for the values shown in the first column, I require the output shown in the 2nd collumn;

    S1_358_801 801
    S1_358_801_PR2 801
    S1_370_733A 733A
    S1_3701_722_BA1 722
    S31_342_902 902

    As can be seen the number of characters between "_" can change and I'm only after the characters after the 2nd "_" but before the 3rd "_" if it exists.

    I have tried using a MID function but to no avail as of yet as occasionally the lenth changes, thus for the length I imagine I would have to use a combination of RIGHT, FIND, LEN and maybe TRIM functions but I dont know how to do this.

    Any Assistance is appreciated.

    Cheers,

    Ben

  2. #2
    Forum Expert
    Join Date
    03-28-2014
    Location
    Hyderabad,India
    MS-Off Ver
    Excel 2013
    Posts
    1,887

    Re: Returning text after the 2nd occurence of a particular character in string

    hi,

    Try This
    =MID(L7,(FIND("_",L7,FIND("_",L7)+1)+1),(FIND("_",L7,FIND("_",L7,FIND("_",L7)+1)+1))-(FIND("_",L7,FIND("_",L7)+1)+1)),

    This will work for second occurrence only.

    Punnam

  3. #3
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Returning text after the 2nd occurence of a particular character in string

    May be this , assuming data in A1 and below.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    ________________________________________________________
    If your problem is solved, update the thread as SOLVED: Go to the top of the first post-Select Thread Tools-Select Mark thread as Solved OR - Go to the first post - Click edit- Click Advance- Just below the word "Title:" you will see a dropdown with the word No prefix.- Change to Solve- Click Save.

    Show your gratitude to the person who helped you solving your problem by clicking on star button at the bottom of such post.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Returning text after the 2nd occurence of a particular character in string

    Someone will probably come up with a more elegant version, but until then, try this...
    =MID(A1,FIND("xx",SUBSTITUTE(A1,"_","xx",2),1)+1,IF(LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))=2,99,FIND("xx",SUBSTITUTE(A1,"_","xx",3),1)-FIND("xx",SUBSTITUTE(A1,"_","xx",2),1)-1))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Returning text after the 2nd occurence of a particular character in string

    =MID(A1,FIND("_",SUBSTITUTE(A1,"_","@",1))+1,IFERROR(FIND("@",SUBSTITUTE(A1,"_","@",3))-FIND("_",SUBSTITUTE(A1,"_","@",1))-1,256))
    Try this
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Returning text after the 2nd occurence of a particular character in string

    I hope the below thread also will help you since it's something related to your post content

    http://www.excelforum.com/excel-prog...ml#post3754303


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  7. #7
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    79

    Re: Returning text after the 2nd occurence of a particular character in string

    Thankyou FDibbins, your function was the first that worked for me but all of them are similar. However, could you explain why you use 99 as the 'value if true' for the IF function. Is this just a random number?

    Cheers,

    Ben

  8. #8
    Forum Expert
    Join Date
    03-28-2014
    Location
    Hyderabad,India
    MS-Off Ver
    Excel 2013
    Posts
    1,887

    Re: Returning text after the 2nd occurence of a particular character in string

    Hi spicey ,

    Have tried the formula which i have given u, post reference is "2".

    It worked fine for me .
    Punnam

  9. #9
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    79

    Re: Returning text after the 2nd occurence of a particular character in string

    Sorry Punnam,

    This doesnt work for me, no matter what I try I get a #VALUE error

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Returning text after the 2nd occurence of a particular character in string

    Quote Originally Posted by Spicey_888 View Post
    However, could you explain why you use 99 as the 'value if true' for the IF function. Is this just a random number?
    Yes, pretty much. Its just a long string that should cater for what would be left after the 2nd _

    edit:Punnam's formula works for 3 _, but not for 2 - as they said in their post
    Last edited by FDibbins; 07-04-2014 at 02:12 AM.

  11. #11
    Forum Expert
    Join Date
    03-28-2014
    Location
    Hyderabad,India
    MS-Off Ver
    Excel 2013
    Posts
    1,887

    Re: Returning text after the 2nd occurence of a particular character in string

    Hi ,

    just replace the cell address From L7 to u r required cell.

    Punnam

  12. #12
    Forum Expert
    Join Date
    03-28-2014
    Location
    Hyderabad,India
    MS-Off Ver
    Excel 2013
    Posts
    1,887

    Re: Returning text after the 2nd occurence of a particular character in string

    hi,

    it is working but partially need some changes .

    Punnam

  13. #13
    Forum Expert
    Join Date
    03-28-2014
    Location
    Hyderabad,India
    MS-Off Ver
    Excel 2013
    Posts
    1,887

    Re: Returning text after the 2nd occurence of a particular character in string

    try this updated formula

    =IFERROR(MID(A1,(FIND("_",A1,FIND("_",A1)+1)+1),(FIND("_",A1,FIND("_",A1,FIND("_",A1)+1)+1))-(FIND("_",A1,FIND("_",A1)+1)+1)),MID(A1,(FIND("_",A1,FIND("_",A1)+1)+1),LEN(A1)))

    Punnam

  14. #14
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Returning text after the 2nd occurence of a particular character in string

    Isn't my solution working as in post #3?

  15. #15
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Returning text after the 2nd occurence of a particular character in string

    Hi,

    =TRIM(MID(SUBSTITUTE(A1,"_",REPT(" ",LEN(A1))),LEN(A1)*2,LEN(A1)))

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  16. #16
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    79

    Re: Returning text after the 2nd occurence of a particular character in string

    As I said, FDibbins result has work best for me, I have also been able to adjust it a little for another application but thankyou for all your suggestions, It is all muchly appreciated.

    Sorry about the delayed reply

    I will now marked as solved.

  17. #17
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Returning text after the 2nd occurence of a particular character in string

    Happy to help and thanks for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Find the last occurence of a text string in an email
    By hmltnangel in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 06-19-2014, 10:13 AM
  2. Replies: 4
    Last Post: 04-06-2014, 01:21 PM
  3. [SOLVED] Returning a character from a string
    By abduljaleel.mca in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-14-2013, 04:18 AM
  4. Replies: 3
    Last Post: 05-03-2012, 04:00 PM
  5. Find the last occurence of a text string in a list
    By NDBC in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-14-2009, 04:22 AM

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