+ Reply to Thread
Results 1 to 5 of 5

Extract number in the middle of text (check from right-to-left)

  1. #1
    Registered User
    Join Date
    01-18-2012
    Location
    JB, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Smile Extract number in the middle of text (check from right-to-left)

    Hi all,

    Need help on this problem. I need to extract postcode from address.
    The postcode size is 5 character. and i think it is easy to check it from right to left because after the postcode, there will not be any number, only text.

    The data :
    1. NO. 106, JALAN LEP 3/4, TMN LESTARI PUTRA, 43300 SERI KEMBANGAN
    2. B3-03-19 PANGSAPURI TANJUNG 1, JALAN MERDEKA VILLA 48000 AMPANG
    3. A-2-3 PANGSAPURI SERI KAYAN USJ 2/1,47610 SUBANG JAYA SELANGOR DARUL EHSAN
    4. J-7229 TAMAN MAJU 40675 JASIN

    Expected outcome :
    1. 43300
    2. 48000
    3. 47610
    4. 40675

    I have tried this solution but i still cant modify it to solve my problem.
    Thank you for your help and attention
    Last edited by diywho; 01-20-2012 at 05:22 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Extract number in the middle of text (check from right-to-left)

    For the wide variety of strings you've presented, I would write a brand new User Defined Function (UDF) to make this simple do via formula. First we add the new function to your workbook:
    Please Login or Register  to view this content.

    How to install the User Defined Function:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save as a macro-enabled workbook (*.xlsm)

    The function is installed and ready to use.

    With the strings in column A, you could put this formula in B1, then copy down:

    =LASTNUM(A1)
    Attached Files Attached Files
    Last edited by JBeaucaire; 01-19-2012 at 01:25 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    365
    Posts
    2,243

    Re: Extract number in the middle of text (check from right-to-left)

    Quote Originally Posted by diywho View Post
    ....after the postcode, there will not be any number, only text...
    if so, one way:

    =MID(A1,MATCH(10,INDEX(--MID(A1,ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1))),1),0))-4,5)
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Extract number in the middle of text (check from right-to-left)

    Haseeb, that is an awesome formula.

  5. #5
    Registered User
    Join Date
    01-18-2012
    Location
    JB, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Extract number in the middle of text (check from right-to-left)

    haseeb...I totally salute you!!!

    JBeaucaire ..thanks a lot for easy to understand step by step. i never know about UDF

    thanks guys...u saved my day

+ 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