+ Reply to Thread
Results 1 to 4 of 4

Extracting the nth number from an alphanumeric string

  1. #1
    Registered User
    Join Date
    04-12-2011
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    67

    Extracting the nth number from an alphanumeric string

    Hi,

    I've been trying out some things I've learned from people here and I'm currently trying to make a formula to extract the nth number from an alphanumeric string. I've managed to get the second, but the formula is getting huge already and so I'm certain there is a neater method. Any tips would be gratefully received.

    Eg.

    if n=1:

    df34 drft 467rtthy43p --> 34
    bn638m 3546mfh939 --> 638

    if n=2:

    df34 drft 467rtthy43p --> 467
    bn638m 3546mfh939 --> 3546

    etc.

    Thanks a lot,

    Chinchin

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Extracting the nth number from an alphanumeric string

    Try adding this User Defined Function (Alt+F11, Insert|Module)

    and paste into the VB editor:

    Please Login or Register  to view this content.
    Then use formula:

    Please Login or Register  to view this content.
    Confirmed with CTRL+SHIFT+ENTER not just ENTER

    Where A1 contains the original string.

    and A2 contain the "n" number you want pulled out.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    04-12-2011
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    67

    Re: Extracting the nth number from an alphanumeric string

    Thanks - works great. Will take me a while to figure out what's going on though so I might have to come back with a question or two.

    I assume this is not possible, or is prohibitively complex, without using vba?

    Chinchin

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Extracting the nth number from an alphanumeric string

    I am sure it can be done without the udf, but I can't think of a nice short way to do it at the moment . There is also a free addin MOREFUNC.XLL that you can use and then use the MCONCAT function or even a regex function...

+ 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