Closed Thread
Results 1 to 12 of 12

Finding numbers in text string

  1. #1
    Registered User
    Join Date
    11-11-2009
    Location
    Reading, England
    MS-Off Ver
    2010
    Posts
    69

    Finding numbers in text string

    Hi,

    In a data report i have a column which contains a mix of text and may contain an 8 digit number which could start in 0.

    for example

    in column A i could have "Hello how are you 01237232 I am fine"

    I wish to extract the number into a seperate column, and would ordinarilly use a mid or left/ right function, however the text infront and behind the number will vary in length, which means i cannot do this.

    The number will always be 8 digits, could start in 0 but will not always, and it may not be present in all the cells in this column.

    Has anyone got any pointers as to how I an achieve this?

    Kind Regards

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

    Re: Finding numbers in text string

    Is it the only number in the string? For a string in A1 this formula will give you the 8 characters starting with the first digit in A1

    =MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&1234567890)),8)

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Finding numbers in text string

    With slightly improved daddy's approach you could find first number and extract it no matter how it's long:

    =LOOKUP(99^99,--("0"&MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),ROW($1:$10000))))

    (OK, "no matter how long" is figurative )

  4. #4
    Forum Contributor
    Join Date
    12-03-2009
    Location
    Providence RI
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    260

    Re: Finding numbers in text string

    Depending on the number of characters... this is an alternative but this is an array formula and would need to be entered with CTRL SHIFT + ENTER. Should go up to 100 #s.

    =MID(A1,MATCH(TRUE,ISNUMBER(1*MID(A1,ROW($1:$100),1)),0),COUNT(1*MID(A1,ROW($1:$100),1)))
    Last edited by Dulanic; 05-11-2010 at 09:17 AM.

  5. #5
    Registered User
    Join Date
    11-11-2009
    Location
    Reading, England
    MS-Off Ver
    2010
    Posts
    69

    Re: Finding numbers in text string

    Daddy long legs That works brilliantly there will occasionally be other numbers, but these will not be 8 digits, is it possible to show an error or blank for these?

    An example is "2), Nimr" or "19), Col" which the formular has returned,

    Zbor, the number will always be 8 digits I think I can get away with the more simple one, but thanks

    Many Thanks
    Last edited by Henry c; 05-11-2010 at 09:19 AM. Reason: mistake

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Finding numbers in text string

    Quote Originally Posted by Henry c View Post
    Zbor, the number will always be 8 digits I think I can get away with the more simple one, but thanks
    Well, you also said: there will occasionally be other numbers, but these will not be 8 digits

  7. #7
    Registered User
    Join Date
    11-11-2009
    Location
    Reading, England
    MS-Off Ver
    2010
    Posts
    69

    Re: Finding numbers in text string

    Quote Originally Posted by zbor View Post
    Well, you also said: there will occasionally be other numbers, but these will not be 8 digits
    Yes there will, but it is only the 8 Digit one I wish to extract.

    Aplologies if this was taken the wrong way, I very much appreciate your advice.

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

    Re: Finding numbers in text string

    This version will only find an eight digit number

    =TEXT(LOOKUP(10^8,MID(SUBSTITUTE(A1," ","x"),ROW(INDIRECT("1:"&LEN(A1)-7)),8)+0),"00000000")

    it returns #N/A if there isn't such a number. You could make that a blank by changing to this

    =TEXT(-LOOKUP(1,CHOOSE({1,2},0,LOOKUP(1,-MID(SUBSTITUTE(A1," ","x"),ROW(INDIRECT("1:"&LEN(A1)-7)),8)+0))),"00000000;;")

  9. #9
    Registered User
    Join Date
    11-11-2009
    Location
    Reading, England
    MS-Off Ver
    2010
    Posts
    69

    Re: Finding numbers in text string

    Thanks so much, great help

  10. #10
    Registered User
    Join Date
    09-19-2012
    Location
    TLV
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Finding numbers in text string

    Quote Originally Posted by Henry c View Post
    Daddy long legs That works brilliantly there will occasionally be other numbers, but these will not be 8 digits, is it possible to show an error or blank for these?

    An example is "2), Nimr" or "19), Col" which the formular has returned,

    Zbor, the number will always be 8 digits I think I can get away with the more simple one, but thanks

    Many Thanks
    It happend to me too and then I figured out the formula was counting ALL the digists in the string, meaning, when there are more numbers further down, and it was "midding" the whole accumulated digits length which resulted in "so many" irrelevant additional characters. check your list and you will see.
    Still this formula is genious!

  11. #11
    Registered User
    Join Date
    01-24-2014
    Location
    Portugal
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Finding numbers in text string

    Hello, I'm new in here, my name is Alfredo and I'm a studant from portugal. I have a work to do that is analyse a meteorological code on execel and divide it is colums.
    I can't find any help on something I need to do. I need to extract every section of text from a string of text and numbers. Here is my problem: METAR LPMT 300900Z 35005KT 300V360 9999 FEW018 12/08 Q1026 (TWR:30.30) RMK HR76 CLD5 FEW080 BLU=
    This is a meteorological code. I want to extract the 300V360 that is always formed by 3numbers,"V",3numbers; but it can be or not in the code, but can apear other "V" in the code, but not "sorounded" by numbers. I can't use the MID function because it can be in diferent places. I think I said it all. Any one can help me?
    Thank you, and sorry for my bad english

  12. #12
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Finding numbers in text string

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

Closed 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