+ Reply to Thread
Results 1 to 16 of 16

extracting numbers from text string and adding them together

  1. #1
    Registered User
    Join Date
    07-24-2012
    Location
    burlington WA
    MS-Off Ver
    Excel 2010
    Posts
    54

    extracting numbers from text string and adding them together

    I have text strings like 12M5R. I need to add those numbers together regardless of how the text string is composed (there is alot of variation).
    Thanks for any assistance

  2. #2
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: extracting numbers from text string and adding them together

    Hi Leif... 1+2+5=8 or 12+5=17?

  3. #3
    Registered User
    Join Date
    07-24-2012
    Location
    burlington WA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: extracting numbers from text string and adding them together

    12+5=17 Sorry for not making that clear

  4. #4
    Registered User
    Join Date
    07-24-2012
    Location
    burlington WA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: extracting numbers from text string and adding them together

    Is there any way to do this? or do I have to do manually?

  5. #5
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: extracting numbers from text string and adding them together

    Sorry Leif,

    I meant to write back, but I was struggling with the VBA function (not my forte)... but I think I figured it out...

    Again, my coding is far from "textbook"... I only learned VBA from trial and error... anyway, check out the function that I created... see if you can use it...

    Contact me if you don't know how to copy the VBA in your worksheet...

    Thanks,
    Dennis

    Re-post: I couldn't figure out a nice formula, so I decided on using VBA... anyone how has any other ideas or improvements or a more proper way to code it, is more than welcome... I like learning on how to do it more "properly"... thanks!
    Attached Files Attached Files
    Last edited by djapigo; 12-03-2012 at 05:06 PM.

  6. #6
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: extracting numbers from text string and adding them together

    Try this Lief

    Please Login or Register  to view this content.
    _____________

    aelgadi

    >>> If I helped, Don't forget to add to my reputation (click on the at left bottom of the post)
    >>> If satisfied with a solution, don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  7. #7
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: extracting numbers from text string and adding them together

    Hi aelgadi,

    See post #3...

  8. #8
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: extracting numbers from text string and adding them together

    I see djapigo,

    How about this
    Please Login or Register  to view this content.
    _________________________

    aelgadi

    >>> If I helped, Don't forget to add to my reputation (click on the at left bottom of the post)
    >>> If satisfied with a solution, don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  9. #9
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: extracting numbers from text string and adding them together

    Nicely done, aelgadi... your code works great and shows a flaw in my declarations... should change Double and Integer to Long...

    Nice work!

  10. #10
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: extracting numbers from text string and adding them together

    Or maybe
    Please Login or Register  to view this content.
    In Excel
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Can you have decimal numbers in the string?
    If so what would you expect from this
    1.2M5R = 1.7, or 8?
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  11. #11
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: extracting numbers from text string and adding them together

    Nice work Morcol but what happen if there is already space in original text string i.e 12M 3Y2 or consecutive letters i.e 12MUL34M

    ___________________

    aelgadi

    >>> If I helped, Don't forget to add to my reputation (click on the star at left bottom of the post)
    >>> If satisfied with a solution, don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Last edited by aelgadi; 12-03-2012 at 11:03 PM.

  12. #12
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: extracting numbers from text string and adding them together

    Thanks djapigo. By the way, still you can use integers djapigo and thanks again

    _____________________________________

    aelgadi

    >>> If I helped, Don't forget to add to my reputation (click on the star at left bottom of the post)
    >>> If satisfied with a solution, don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Last edited by aelgadi; 12-03-2012 at 11:03 PM.

  13. #13
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: extracting numbers from text string and adding them together

    Marcol ,

    Tody I had a chance to test your codes and it works like a charm
    a big star from me

    ____________________

    aelgadi

    >>> If I helped, Don't forget to add to my reputation (click on the star at left bottom of the post)
    >>> If satisfied with a solution, don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  14. #14
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: extracting numbers from text string and adding them together

    Quote Originally Posted by aelgadi View Post
    Nice work Morcol but what happen if there is already space in original text string i.e 12M 3Y2 or consecutive letters i.e 12MUL34M

    ___________________

    aelgadi
    By replacing all non digits with a space we get a string with any number of spaces, some in groups, others as singletons.

    Worksheetfunction.Trim() removes all redundant spaces, leading, trailing, and internally. we can now replace the spaces with "+"

    If you use the VBa function Trim() only leading and trailing spaces are removed, then you'll possibly get multiple consecutive "+"s when you replace the spaces. In that case Evaluate() will fail.

  15. #15
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: extracting numbers from text string and adding them together

    I see Marcol thanks.

  16. #16
    Registered User
    Join Date
    07-24-2012
    Location
    burlington WA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: extracting numbers from text string and adding them together

    I used marcol's, it worked very well. Thank you guys/gals.

+ 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