+ Reply to Thread
Results 1 to 10 of 10

split stringer in letters and numbers

  1. #1
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    split stringer in letters and numbers

    Let's say I have this stringer: "abc123", how can I split this in "abc" and "123" ? the number of letters and numbers is not the same but all the time I have first letters and after that numbers. For example I can have this kind of stringers: aa1, ea23, ef5 etc.
    Last edited by iscar_marius; 04-07-2010 at 03:28 AM.

  2. #2
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    Re: split stringer in letters and numbers

    I found this code:

    Please Login or Register  to view this content.
    How can I modify it so the result will be a stringer "123" ?

  3. #3
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: split stringer in letters and numbers

    Hi,

    The first step is to determine the position of the first number in your text string
    Please Login or Register  to view this content.
    Then, if the functions Left() and Right() you will be able to split all your strings ...

    HTH

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: split stringer in letters and numbers

    JR, easiest to append the string with all integers, eg:

    Letters

    B8: =LEFT(A8;MIN(FIND({1\2\3\4\5\6\7\8\9\0};A8&1234567890))-1)

    Numbers are thus

    C8: =0+REPLACE(A8;1;LEN(B8);"")

    Or

    C8: =0+SUBSTITUTE(A8;B8;"")

    (if you prefer the number as string remove the 0+ coercion)


    edit: revised delimiters per OP locale
    Last edited by DonkeyOte; 04-07-2010 at 02:50 AM.

  5. #5
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    Re: split stringer in letters and numbers

    Quote Originally Posted by JeanRage View Post
    Hi,

    The first step is to determine the position of the first number in your text string
    Please Login or Register  to view this content.
    Then, if the functions Left() and Right() you will be able to split all your strings ...

    HTH
    Can I use this in vba? I will try to read more about this ... A8 is a range?

    The code from my previous post is working but the results is 3 msgboxes: msgbox1is 1,msgbox2 is 2, msgbox3 is 3. Is not possible to unify this values ?

  6. #6
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    Re: split stringer in letters and numbers

    I really need to do this with vba code. I need to combine this with other vba code that I have.
    Thank you for your answer!

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: split stringer in letters and numbers

    Quote Originally Posted by iscar_marius
    Is not possible to unify this values ?
    Please elaborate regards the above - unify ?

  8. #8
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    Re: split stringer in letters and numbers

    Quote Originally Posted by DonkeyOte View Post
    Please elaborate regards the above - unify ?
    Using that code, the result will be all the numbers from the stringer separately. I need all of this values toghether in a stringer. unify = put toghether ( I don't know if unify is a english word ). In the above example, I need a new stringer "123".
    Sorry for my bad english!

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: split stringer in letters and numbers

    Simply remove the For Next loop which is presently iterating the resulting number char by char and return the variable as a whole, ie:

    Please Login or Register  to view this content.
    rather than

    Please Login or Register  to view this content.

    FWIW - you could avoid the Regular Expressions and use for ex.:

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 04-07-2010 at 03:20 AM.

  10. #10
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    Re: split stringer in letters and numbers

    This is exactly what I need. 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)

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