+ Reply to Thread
Results 1 to 16 of 16

Extracting Numbers from text

Hybrid View

  1. #1
    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

    The most versatile way is to use VBa.

    Try this UDF
    Function SumCell(rng As Range)
        Dim strtmp As String
        Dim n As Long
        
        For n = 1 To Len(rng)
            If Asc(Mid(rng, n, 1)) >= 48 And Asc(Mid(rng, n, 1)) <= 57 Then
                strtmp = strtmp & Mid(rng, n, 1)
            Else
                strtmp = strtmp & " "
            End If
        Next
        strtmp = WorksheetFunction.Trim(strtmp)
        SumCell = Evaluate(Replace(strtmp, " ", "+"))
        
    End Function
    Use in worksheet
    Formula: copy to clipboard
    =SumCell(A3)
    Attached Files Attached Files
    Last edited by Marcol; 12-10-2012 at 10:51 AM.
    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.

  2. #2
    Registered User
    Join Date
    12-10-2012
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Extracting Numbers from text

    Marcol this works perfectly!

    I will need to school myself on udf instalation and usage. Doesn't look to tuff for this newbie.

    Thank you very much.

  3. #3
    Registered User
    Join Date
    12-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Extracting Numbers from text

    What about if your numbers are formatted in tenths and have ( ) around them? Such as:

    ASDF(2.5); ASDF (3.6); ASDF (5.8)

    Any way to get it to get you the total of the numbers in the same cell in the same format and only the numbers in between the ( )?
    Last edited by mstubbs; 12-10-2012 at 06:35 PM.

  4. #4
    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

    Quote Originally Posted by mstubbs View Post
    What about if your numbers are formatted in tenths and have ( ) around them? Such as:

    ASDF(2.5); ASDF (3.6); ASDF (5.8)

    Any way to get it to get you the total of the numbers in the same cell in the same format and only the numbers in between the ( )?
    Assuming there are no "."s (dots) in the string, other than the decimal points.

    Change the function to this ...
    Function SumCell(rng As Range)
        Dim strtmp As String
        Dim n As Long
        
        For n = 1 To Len(rng)
            If Asc(Mid(rng, n, 1)) >= 48 And Asc(Mid(rng, n, 1)) <= 57 Or Asc(Mid(rng, n, 1)) = 46 Then
                strtmp = strtmp & Mid(rng, n, 1)
            Else
                strtmp = strtmp & " "
            End If
        Next
        strtmp = WorksheetFunction.Trim(strtmp)
        SumCell = Evaluate(Replace(strtmp, " ", "+"))
        
    End Function

  5. #5
    Registered User
    Join Date
    12-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Extracting Numbers from text

    Thank you Marcol, I appreciate it. This worked somewhat, the only problem I have now is that I only want the numbers inside the ( ) to be totaled. If I add numbers outside of the ( ) it is still including them in the sum. Any ideas?

  6. #6
    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

    Hi mstubbs

    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. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

    I answered your first query in this thread because I felt it was relevant to the OPs' question.

    You are now asking something quite different, and as the OP has marked the thread [SOLVED], better you start your own thread.

    I suggest a title such as "Sum only numbers in brackets in a cell"

    PM me when you have done this and I will post the UDF solution I have waiting for you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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