+ Reply to Thread
Results 1 to 7 of 7

Extract the first Number from a Text String

  1. #1
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Extract the first Number from a Text String

    Hi
    I need some help in extracting a number from the beginning of a text string. For example:
    465FS+8weeks should return 465
    34SS-3days should return 34
    2345FF-7wks should return 2345
    Any help appreciated.
    Kind regards
    Tony
    Last edited by ARGK; 12-22-2013 at 05:33 PM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Extract the first Number from a Text String

    ARGK,

    Why not 2345??? If it is 2345 then here's a function for you:

    Please Login or Register  to view this content.
    Directions for running the routine(s) just supplied

    Copy the code to the clipboard

    Press ALT + F11 to open the Visual Basic Editor.

    Open a macro-enabled Workbook or save your Workbook As Macro-Enabled

    Select “Module” from the Insert menu

    Type "Option Explicit" then paste the code under it

    On the Spreadsheet type "=TopNo(" Select the cell with the data, close the parentheses.

    And, you should be ready to go
    Last edited by xladept; 12-22-2013 at 05:32 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Extract the first Number from a Text String

    Hi xladept
    Well spotted, missed that one :-).
    Tony

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,942

    Re: Extract the first Number from a Text String

    Try this....
    =LOOKUP(99^99,--("0"&MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),ROW($1:$10000)))) Courtesy of:*Ron Coderre
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Extract the first Number from a Text String

    Many thanks for the responses guys, I will try them over the holidays.
    Kind regards
    Tony

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Extract the first Number from a Text String

    Will any of the numbers start with leading zeros?

    00123

    Is there a limit as to how long the number string will be? For example, the longest string will not exceed 6 digits.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Registered User
    Join Date
    05-10-2013
    Location
    Pomáz, Hungary
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: Extract the first Number from a Text String

    Try this if the numbers to extract are not longer than 12 digits; enter it with Shift-Ctrl-Enter into B1:

    =MAX(IFERROR(--MID(A1,1,{1,2,3,4,5,6,7,8,9,10,11,12}),""))

+ 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. extract number and email id from a text string
    By meegosh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-17-2013, 02:04 PM
  2. [SOLVED] How to Extract A Number from String if Text within the String Equals XYZ
    By tyrsfury in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-15-2012, 03:30 PM
  3. Extract number data string from text
    By lamatao in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-03-2009, 04:27 PM
  4. Extract number from text string
    By jjjjj55555 in forum Excel General
    Replies: 2
    Last Post: 04-04-2007, 04:38 PM
  5. Extract a number from a text string?
    By Brian in forum Excel General
    Replies: 8
    Last Post: 01-09-2006, 05:20 PM

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