+ Reply to Thread
Results 1 to 7 of 7

Extract numbers from a string

  1. #1
    Registered User
    Join Date
    08-24-2010
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    3

    Unhappy Extract numbers from a string

    hello,

    I have a long string of characters and I want to extract only specific numbers from the string. I am very new to coding in excel, can someone please tell me how can I do it.

    For example:

    I have a string which says
    "customer A purchased napkins, meat and a box of ice cream ( product no 3094844 7876393) "
    I just want to extract the numbers which are in the paraenthesis 3094844,7876393

    It might be possible that there is only one product number or more than one. and these numbers always appear in paraenthesis after word "product no".

    Please someone can help, thanks in advance!

  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 numbers from a string

    This function will work on your data, it's a new formula you can use in this 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

    =============
    The function is used in an empty cell like so:

    =NUMSTR(A1)
    =NUMSTR(A1:A3)

    ...or

    =NUMSTR(A1, ",")
    =NUMSTR(A1:A3, "-")


    This newer version lets you put the delimiter to use as an optional second parameter.

    The function will search all the words in your text string and try to determine which are numeric and display ALL of them in a delimited string.


    Attached is a sample workbook with the UDF installed and demonstrated for you.
    Attached Files Attached Files
    Last edited by JBeaucaire; 08-24-2010 at 11:21 PM. Reason: Better version, new.
    _________________
    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
    Registered User
    Join Date
    08-24-2010
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Extract numbers from a string

    Thank you for the code. Sorry I forgot to mention that in the description there can be other numbers too. For example: "Customer A, (ID 3465) purchased milk can and ice cream (product no 7896542 5678432) from store ID 45"

    when I ran your code it returned me back all the numbers including 3465, 45.
    I just want to extract numbers which appear in parenthesis with word "product no" i.e (product no 7896542 5678432)

    can you please help me with this.. no matter how long is description, whatever other numbers are I am just looking to extract numbers when they appear in parenthesis witht he word product no.

    Thank you so much for the help, I will be looking forward to your reply

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Extract numbers from a string

    Your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us help you!

    Read this to understand why we ask you to do this.
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    08-24-2010
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Extract numbers from a string

    sorry for that. I am a newbee to a code, have a deadline on my head thats why I was looking for a quick reply. I will take care of it next time.
    here in the link of the other forum

    http://www.mrexcel.com/forum/showthr...39#post2421739

  6. #6
    Registered User
    Join Date
    06-03-2011
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2010
    Posts
    1

    Extract numbers from a text string

    Hi I'm new at this and in need of help.
    I have a prize list on notepad that i transfered to excel 2010, and I need to extract the prices from each text string and place them on the cell on the right.
    Example:

    CPU AMD ATHLON II 450 X3 AM3 95.14U$S
    CPU AMD ATHLON II 635 X4 AM3 126.36U$S
    CPU AMD ATHLON II 640 X4 AM3 1821.36U$S
    CPU AMD ATHLON II 645 X4 AM3 129.07U$S
    CPU AMD PHENOM 9550 X4 AM2 8.24U$S
    CPU AMD PHENOM II 555 X2 AM3 BLACK 108.83U$S
    CPU AMD PHENOM II 560 X2 3.3 7MB 129.07U$S



    the thing is that the name of the articles a lot of times have numbers, so I'm looking for something that would extract just the price. Something that would extract a string of numbers starting from right to left until it hits a "blank space", while keeping the comas.

    This would help me a lot, thanks!

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Extract numbers from a string

    Welcome to the forum.

    Unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

+ 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