+ Reply to Thread
Results 1 to 10 of 10

Extract Number in Column + Delete the rest

  1. #1
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Extract Number in Column + Delete the rest

    Hi,
    I have the following which is in a column.
    Please Login or Register  to view this content.
    I need to extract the number in this column and delete the rest.
    I have tried text to column with fixed width but the number is in various parts of the column....

    any ideas...
    Last edited by pr4t3ek; 01-12-2009 at 01:51 AM.
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  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
    Press Alt-F11 to open the VBEditor
    Click in Insert > Module
    Paste in the following code:
    Please Login or Register  to view this content.
    Press Alt-Q to exit the VBEditor.

    You've just added a new function to your sheet called LetterOut.

    If a cell has your data in it, perhaps A2, then in B2, put this formula:

    =LetterOut(A2)

    Copy that down to get all the account numbers out of the strings.

    Now highlight the entire range of cells you just created, and COPY, EDIT > PasteSpecial > Values. Now you have the account numbers and the formulas have been removed.
    _________________
    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 Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    hi, ive done exactly that but im getting a "#NAME?" error....

  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
    Quote Originally Posted by pr4t3ek View Post
    hi, ive done exactly that but im getting a "#NAME?" error....
    Post up the book, let's take a look....ooh, it rhymes.

  5. #5
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    ahh anyway for me to add it to the personal.xls instead of the book itself? because im trying to create a macro which does this...

    also, please see attached the file, i dont want it to copy the 6 - **
    i just want the long number ***
    ..
    Attached Files Attached Files

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    The UDF isn't going to work then, at least not without some "tweaking" I think might be unnecessary. It appears that the code is in the same place, at least as far as your sample goes.

    In C4, enter this formula and copy it down:

    =LEFT(RIGHT(B4,33),10)

  7. #7
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    oh yeh tats cool, that works... cheers mate!

  8. #8
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    nah hold uip lol
    it aint working

    e.g:
    Please Login or Register  to view this content.
    the last row is alrite.. but not the ones above..

    sometimes it has the E5 or something before the - but sometiems it doesnt.. so thats my prob.. otherwise my text to column would work too

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    The formula gives the first 10 digits out of the LAST 33, so since last 33 digits all start with the numeric string, I can't see in your sample what the problem is. I'm using that formula on your posted book above and it's working, so something is different in yours.

    Leave it as is not working, and post it again.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello PD,

    Here is macro that uses pattern matching to extract the number. The function is set to look for a number that is at least 5 digits long and no more than 10 digits. I didn't know if these numbers digit count would change. You set the limits differently if you need to.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

+ 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