+ Reply to Thread
Results 1 to 12 of 12

Separate text from numbers

  1. #1
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Separate text from numbers

    Hey all,

    I have cell with lot of texts, punctuations and numbers all mixed together,
    example :

    private-4089 AND road ESCORT,trailer-4111 & test vehicle

    I need to remove all texts and keep the numbers only: 4089, 4111

    then I hope I can do text to column to put each number in a cell

    thanks for usual help

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

    Re: serperate text from numbers

    you could extract the numbers see attached will do 3 numbers
    Attached Files Attached Files
    "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

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: separate text from numbers

    If you want a simple formula and the ability to extract as many individual numbers as there may be, you could add a custom function to your worksheet. It would evaluate the entire text string and pull out all numeric values.

    If your text string were in A1, then this formula in B1:

    =NUMS(A1)
    ..would result in 4089, 4111

    Or:
    =NUMS(A1, "-")
    ...would result in 4089-4111 by using the optional second parameter to use a custom delimiter.

    Here's the UDF I have for this:
    Please Login or Register  to view this content.
    I highlighted in red the only part of the code you might need to edit, it's the characters to search for in the string and replace with spaces... so far just a dash, comma and ampersand.

    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 your sheet

    The function is installed and ready to use.
    _________________
    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!)

  4. #4
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Re: separate text from numbers

    @JB

    this was very helful and detailed..thanks

    however i am getteing value "none" in B if the number and text in A are joined
    private4089,trailer4111

    can this be fixed ?
    many thanks
    Last edited by DonkeyOte; 02-10-2010 at 02:51 AM. Reason: quote removed and replaced with @JB

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: separate text from numbers

    Please don't quote previous posts for no reason, it just clutters the thread making it hard to read. Use the QUICK REPLY box below.

    Why are you changing your text string syntax now? The first was simple and usable. Are you changing it now for some good reason? If not, don't join the text and numerics that way. The UDF works and merging the text that way means the whole thing would need to be redone in a far less efficient way.

  6. #6
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Re: separate text from numbers

    i used find and replace with
    it works ok
    thank for your help

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Separate text from numbers

    legolas, given it is your intention to split the numbers I confess I'm not sure why you chose to ignore Martin's example ?
    The functions provided would extract the numbers to B & C automatically - for either syntax.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Separate text from numbers

    If Martin and I have taken care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated. It is found across from the "time" in each of our posts.)

  9. #9
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Re: Separate text from numbers

    @ DonkeyOte
    Martin's formula is very good if i could add more than 3 extractions, so far i could not figure out how add some more, i hope it can be edited then it will be perfect

    cheers

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

    Re: Separate text from numbers

    how many are you likely to need?
    here is a (not very efficient udf )that will extract all numbers into one cell .then copy paste special values then split with text to columns
    use as =remove_text(a1) and drag down

    Please Login or Register  to view this content.
    Last edited by martindwilson; 02-10-2010 at 11:12 AM.

  11. #11
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Re: Separate text from numbers

    Thanks Martin
    the latest solved my problem (almost)
    thanks for your time

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Separate text from numbers

    FWIW - if you opted for UDF - Regular Expressions may be worth considering...

    Please Login or Register  to view this content.

    Assume string in A1, numbers to go in B1, C1 etc...

    Please Login or Register  to view this content.

    The second variable is optional - ie should you only be looking to return a single numeric value (first) it could be omitted - in this case we increment the value to return 1st, 2nd, 3rd etc...

    Not very effiicient though doing this with functions though IMO...a sub routine would be better.

    EDIT:

    if you want the output for finds to be numeric adjust the 2nd NumberExtract line to:

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 02-11-2010 at 09:18 AM.

+ 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