+ Reply to Thread
Results 1 to 20 of 20

Formula needed to extract numbers from alpha numerical entry please

  1. #1
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Formula needed to extract numbers from alpha numerical entry please

    Hi

    I'm hoping someone can help with a problem I have. I have a sheet with thousands of rows of ID's which are made up of a series of letters, numbers, underscores and or spaces. Within the sheet there are numerous duplicates so I need to able extract the numerical element, which is the key data to be able to identify the duplicates.

    The numbers I need to extract are mainly 6 and 7 digits long however don't always sit in the same place within the ID. I don't need the 3 digit number sequences, just the 6 & 7 number sequences

    e.g

    AB_123_456789_Jones
    CD_131_7654321_Smith
    AB_123_Jones_456789

    I've found a formula that strips out all the numbers, however it also included the 3 digit numbers which I don't want. I've also used Text To Columns to break up the ID across a number of columns however that leaves me with 2 and sometimes 3 columns where a 6 digit ID appears

    Is there a simple way to extract the number if it's a certain length? i.e. 6 or 7 digits long

    I hope that all makes sense and I've provided sufficient information

    Many thanks in advance

    Greg

  2. #2
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: Formula needed to extract numbers from alpha numerical entry please

    =LOOKUP(10^99,--MID(A1,MAX(IF((--ISNUMBER(--MID(A1,ROW($1:$25),1))=0)*
    ISNUMBER(--MID(A1,ROW($2:$26),1)),ROW($2:$26))),ROW($1:$25)))
    Confirm Control+shft+Enter
    If you are http://www.excelforum.com/image.php?type=sigpic&userid=125481&dateline=1392355029happy with the results, please add to the contributor's
    reputation by clicking the reputation icon (star icon).




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.
    To undo, select Thread Tools-> Mark thread as Unsolved.
    http://www.excelaris.co.uk

  3. #3
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Formula needed to extract numbers from alpha numerical entry please

    Hi Robert

    Many thanks for your very quick response

    The formula works brilliantly for the most part, there is one slight problem which is my fault as I've just noticed something I didn't mention in the original post so many apologies.

    There are also some entries where it only includes alphabetical characters, the 3 digit numerical code and a colleague name

    i.e. GL_131_G Clark

    Is there a way to amend the formula to only return numbers of a certain length, or perhaps easier to exclude 3 digit numbers?

    Many thanks

    Greg

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Formula needed to extract numbers from alpha numerical entry please

    is the 3 digit code always first?
    have you got more examples?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Formula needed to extract numbers from alpha numerical entry please

    Hi

    Yes the 3 digit code always appears in the same position

    GL_131_E FULTON
    GL_131_B Slowey
    GL_131_P RYBAK

    Thanks

    Greg

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Formula needed to extract numbers from alpha numerical entry please

    Try this formula

    =IFERROR(AGGREGATE(14,6,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),{6,7})+0,1),"No number")
    Audere est facere

  7. #7
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Formula needed to extract numbers from alpha numerical entry please

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


    Edited to include this variation that excludes numbers greater than 9999999:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Note: that formula gets tripped up if the 6 or 7 digit number begins with a zero.

    Is that something you can work with?
    Last edited by Ron Coderre; 01-08-2014 at 05:16 PM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  8. #8
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Formula needed to extract numbers from alpha numerical entry please

    Hi Daddylonglegs - That formula works excellently thank you!

    Hi Ron - There are occasions where a 7 digit number could begin with a zero so unfortunately I wouldn't be able to use it

    Just to add to the thread and plea for help if I may, on the entries where there is no 6 or 7 digit number, just the leading 2 letters, the 3 digit code plus a colleagues name, is there a simple way to extract the name element so I could also check for duplicates there?

    i.e.

    GL_131_G Clark
    GL_131_J MCCREADY
    TB_GAQ_T ALICE_Green

    From what I can see looking down the list, where there is no 6/7 digit number, the name always starts in the same position, namely 8 characters from the left. Mostly with the initial first followed by a space or underscore, and then the surname. There are also a few instances where the surname is first followed by the initial although not sure if that would impact any formula

    Many thanks again for all your help with this guys

    Greg

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Formula needed to extract numbers from alpha numerical entry please

    You could edit my suggestion so that the "No number" part is replaced by the name, e.g.

    =IFERROR(AGGREGATE(14,6,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),{6,7})+0,1),REPLACE(A1,1,7,""))

  10. #10
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Formula needed to extract numbers from alpha numerical entry please

    Genius Daddylonglegs!

    Works a treat and has highlighted over 900 duplicates in the sheet which is what I was hoping for

    Thanks so much for all your help guys, keep up the great work

    Thanks

    Greg

  11. #11
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Formula needed to extract numbers from alpha numerical entry please

    Hello all

    Unfortunately daddylonglegs' formula doesn't work when used at work as we have 2007 which I failed to mention on my original post, I hadn't considered it to be honest so apologies for the schoolboy error.

    Is anyone aware of a formula I can use on 2007 that would return the 6 or 7 long number, or the colleague name and ignore the 3 digit number?

    Many thanks

  12. #12
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formula needed to extract numbers from alpha numerical entry please

    I would suggest to use vba UDF function

    Use formula:

    =NumberOut(SUBSTITUTE(A1,"_",", "))

    Code:

    Please Login or Register  to view this content.

    A
    B
    1
    AB_123_456789_Jones 456789
    2
    CD_131_7654321_Smith 7654321
    3
    AB_123_Jones_456789 456789
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  13. #13
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Formula needed to extract numbers from alpha numerical entry please

    Hi Alkey

    Thanks for your reply

    You're going to have to forgive my vba knowledge however how do I apply the code to the sheet to return the results?

    I've copied the code into the editor however I'm not altogether sure what else I need to do

    Will the code also work if there isn't a 6 or 7 digit number? Where there isn't a 6/7 digit number I need to return the name instead?

    i.e.

    GL_131_G Clark
    GL_131_J MCCREADY
    TB_GAQ_T ALICE_Green

    Many thanks

    Greg

  14. #14
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formula needed to extract numbers from alpha numerical entry please

    When you open Vb editor, click on Insert, and select Module. Paste code into module and close Vb editor.

    The formula below will return 6 or seven digit numbers or name if no said number is found.

    *Please note that the name may not be complete because of inconsistent data.

    **This assumes that data starts in A1

    =IF(NumberOut(SUBSTITUTE(A1,"_",", "))="",TRIM(RIGHT(SUBSTITUTE(A1,"_",REPT(" ",255)),255)),NumberOut(SUBSTITUTE(A1,"_",", ")))

    A
    B
    1
    AB_123_456789_Jones 456789
    2
    CD_131_7654321_Smith 7654321
    3
    AB_123_Jones_456789 456789
    4
    GL_131_G Clark G Clark
    5
    GL_131_J MCCREADY J MCCREADY
    6
    TB_GAQ_T ALICE_Green Green
    Last edited by AlKey; 01-14-2014 at 04:24 PM.

  15. #15
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Formula needed to extract numbers from alpha numerical entry please

    Hi

    Not sure what I'm doing wrong however it's returning '#value!', should the code work on 2011 as well as 2007

    This is what I'm doing...

    Data starts in A1 on my sheet
    Opening Vb editor, clicking insert module, pasting the code from your original post in and closing Vb editor
    Copying and pasting the formula on your 2nd post into the cell where I want the number/name to populate which is when I get #value!

    Any thoughts? Anything obvious I'm doing wrong?

    Thanks

  16. #16
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formula needed to extract numbers from alpha numerical entry please

    Please see attached macro-enabled file.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Formula needed to extract numbers from alpha numerical entry please

    Hi
    Thanks for that, it's also showing #value! when I open the sheet, could it be the version of Excel I'm using at home which is 2011 for the Mac?
    Thanks

  18. #18
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formula needed to extract numbers from alpha numerical entry please

    Most likely security settings. I am not familiar with Mac Office so I can't give you directions on how to enable macros in your version of Office.

  19. #19
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Formula needed to extract numbers from alpha numerical entry please

    Macro's are enabled. A pop up box appears when you open a sheet containing macro's asking if you want to enable them which I did. I've also just tested with a basic macro and it worked fine so really don't know.

    Can code differ between Excel versions do you know or is it universal and should work across all platforms?

  20. #20
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Formula needed to extract numbers from alpha numerical entry please

    Alkey - I'll test the code in work tomorrow and hopefully it should work ok

    Thanks for all your help

+ 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. Replies: 6
    Last Post: 02-17-2024, 04:29 PM
  2. Formula to create alpha numerical SKU's
    By Mhunt in forum Excel - New Users/Basics
    Replies: 10
    Last Post: 01-10-2013, 07:10 AM
  3. Alpha/Numerical numbers
    By rhani111 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-27-2006, 09:09 PM
  4. [SOLVED] how do you change excel columns from numerical to alpha
    By ronnie t blonde in forum Excel General
    Replies: 2
    Last Post: 05-16-2006, 05:45 AM
  5. Numerical grade to Alpha character
    By capecrusader in forum Excel General
    Replies: 6
    Last Post: 08-20-2005, 09:05 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