Extract and SUM numbers from a string

I have no idea how to begin doing that

  • Open your Excel file.
  • Press Alt-F11, the VBA Editor window opens.
  • Select Insert-Module in menu, new module windows opens.
  • Insert the below code into the module window:

    Public Function ParseAndSum(source As String) As Integer
    Dim tmp() As String, i As Integer
    tmp = Split(source, ",")
    For i = LBound(tmp) To UBound(tmp)
        ParseAndSum = ParseAndSum + Val(tmp(i))
    Next i
    End Function
    
  • Close VBA editor.

  • Select destination cell (B1 for example).
  • Press "function" knob (fx), Function Master window opens.
  • Select "User-defined functions" category, select ParseAndSum function, click Next.
  • Click source cell (A1), its address inserts into Source field.
  • Click OK.

That's all.

PS. Do not forget to enable macros execution in Excel preferences.


This can be done with a formula:

=SUMPRODUCT(--TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",99)),(ROW($A$1:INDEX(A:A,LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1))-1)*99+1,99)))

This splits on the , and iterates the parts and sums them.

enter image description here