+ Reply to Thread
Results 1 to 7 of 7

Thread: Sum values in text strings across multiple cells

  1. #1
    Valued Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    477

    Sum values in text strings across multiple cells

    I'd like to use a formula to sum the values found in text strings across multiple cells.

    For example
    Cell A1 = 18K,18Mo,18Co
    Cell B1 = 2Na,2Si,2K,2Mg,2Fe,2Ca,2Al

    I would like to have a formula in C1 that will return 68 (the sum of all the values in these two strings)

    The text strings in each cell can be variable length and the numbers can be one, two or three digit numbers but will always be proceeded by a comma (except for the first occurance).

    Any help would be greatly appreciated.

    Thanks
    Last edited by bhofsetz; 01-17-2012 at 12:06 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    MS Office Excel 2007
    Posts
    841

    Re: Sum values in text strings across multiple cells

    68. The total is 68 not 66
    Regards
    Special-K

    I rarely return to a problem once I've answered it so make sure you clearly define what the trouble is.

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    MS Office Excel 2007
    Posts
    841

    Re: Sum values in text strings across multiple cells

    I'm wondering if you could use some kind of inline REPLACE to change all letters and commas with a "+" sign, add a 0 to the end and evaluate that.
    So you end up with

    18+18+18+0
    then evaluate that.

    Something like EVAL(REPLACE([A...Z,],UPPER(A1),"+")&"0")

    Still thinking...
    Regards
    Special-K

    I rarely return to a problem once I've answered it so make sure you clearly define what the trouble is.

  4. #4
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    896

    Re: Sum values in text strings across multiple cells

    check attachment with UDF function
    Attached Files Attached Files
    Last edited by tom1977; 01-16-2012 at 04:49 PM.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  5. #5
    Valued Forum Contributor
    Join Date
    02-20-2007
    Location
    South Africa
    MS-Off Ver
    2007
    Posts
    488

    Re: Sum values in text strings across multiple cells

    Hi bhofsetz,

    Check the attached Workbook, and see if that will help you. That is all I can come up with now.

    Good Luck,

    Hope it helps!
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Click the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  6. #6
    Valued Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    477

    Re: Sum values in text strings across multiple cells

    Thanks for the suggestions.

    Special-K that is a good idea but anything I was able to come up with would require nesting multiple SUBSTITUTE functions for each letter of the alphabet

    tom1977 I was hoping to avoind a UDF but I think that may be the way to to and the one you posted is very straightforward, Thanks!

    Winon your suggestion works but I was hoping for something that would automatically pluck the numeric values out of the text string and give the result rather than having to do any manual manipulation.

    Thanks again and if anyone else has further suggestions or refinement of anything so far I'd appreciate it.

  7. #7
    Valued Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    477

    Re: Sum values in text strings across multiple cells

    Thanks for the UDF tom1977. That is what I was looking for.

    My original post asked for handling items in cells A1 and B1 which tom1977's UDF worked perfectly for.

    I modified UDF so that it allows you enter a range into the UDF and it will ignore empty cells in that range

    Function JobLogSum(a) As Variant
    Dim x As Long, expr As Variant, tbl() As Variant, y&, z&
    Application.Volatile
    For x = 1 To a.Count
        If a(x) <> "" Then
          expr = Split(a(x), ",")
          ReDim Preserve tbl(0 To UBound(expr))
            For y = 0 To UBound(expr)
                tbl(y) = Val(expr(y))
                z = z + Val(expr(y))
            Next y
        End If
    Next x
    
    JobLogSum = z
    
    End Function
    Thanks again for all the suggestions.

+ 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.2.0