+ Reply to Thread
Results 1 to 12 of 12

Get characters of string

  1. #1
    Registered User
    Join Date
    11-21-2014
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    11

    Get characters of string

    Hi all,

    I'd kindly ask you to help with this.
    I have the following string and I want to use a formula to extract only the L63004

    C:\VISION Projects\MyATIrecorders\2328_14022013_1800_L63004_NEDC_cst.rec

    The string will change it's format based on the user but I want always to extract a letter and the following 5 numbers. It could be M59102 or E21953, etc. The good thing is that the letter and the following 5 numbers are always separated from the rest of the string by _

    Thank you,
    Pedro

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Get characters of string

    Are there always the same number of underscores?


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


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

    Re: Get characters of string

    Based on TMS's method

    =MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,"_",CHAR(1),3))+1,6)

    assuming there are no underscores in the pathname
    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.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Get characters of string

    My method? I only asked a question I do like the choice of CHAR(1) as the replacement as it's highly unlikely to be found in the data

    But yes, I'd have done something similar. Maybe also changed the next underscore as the chances are the next question will be, what if there are more or less characters.

    Cheers, TMS

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

    Re: Get characters of string

    I didnt not want to give you credit :-)
    Not sure where I found this solution so the CHAR(1) is not my idea.

    Good idea about the next underscore!

  6. #6
    Registered User
    Join Date
    11-21-2014
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    11

    Re: Get characters of string

    The underscores are always in there, but its number is not always the same. The characters I want are always in between underscores though.

  7. #7
    Registered User
    Join Date
    11-21-2014
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    11

    Re: Get characters of string

    Quote Originally Posted by Special-K View Post
    Based on TMS's method

    =MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,"_",CHAR(1),3))+1,6)

    assuming there are no underscores in the pathname
    It worked like a charm
    Thank you very much

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

    Re: Get characters of string

    Quote Originally Posted by peetman View Post
    It worked like a charm
    Thank you very much
    He means you too TMS :-)

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Get characters of string

    He means you too TMS :-)
    Just so I can feel that I can take some credit ...

    Formula: copy to clipboard
    Please Login or Register  to view this content.



    Regards, TMS




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  10. #10
    Registered User
    Join Date
    11-21-2014
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    11

    Re: Get characters of string

    Hello again,
    So I changed my file path and the code is retrieving the wrong answer. What I would like on this case is K57239
    T:\2456_K57239_2421_05_07.rec

    Could you please help to make the formulas above more robust.

    Thanks in advance,
    Pedro

  11. #11
    Registered User
    Join Date
    05-10-2013
    Location
    Pomáz, Hungary
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: Get characters of string

    Try this formula (confirm with Ctrl-Shift-Enter):

    =MID(A1,MATCH(1,(MID(A1,ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1))),1)>="A")*ISNUMBER(1*MID(A1,ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1)))+1,5)),0),6)

  12. #12
    Registered User
    Join Date
    11-21-2014
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    11

    Re: Get characters of string

    Quote Originally Posted by István Hirsch View Post
    Try this formula (confirm with Ctrl-Shift-Enter):

    =MID(A1,MATCH(1,(MID(A1,ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1))),1)>="A")*ISNUMBER(1*MID(A1,ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1)))+1,5)),0),6)
    It is working
    Thank you very much.

+ 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. Add characters into string
    By Knarf1968_1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2015, 06:09 AM
  2. [SOLVED] Macro to create a new line within a text string if specific characters appear mid-string
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2014, 11:32 AM
  3. Replies: 7
    Last Post: 07-25-2014, 08:21 AM
  4. [SOLVED] Extract left characters from string with exception of 2 right characters
    By sweetkel23 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-16-2012, 10:45 PM
  5. Replies: 0
    Last Post: 08-29-2005, 11:03 AM

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