Add numbers in a single cell

cdb5341mb

New Member
Joined
Apr 2, 2013
Messages
33
Hello , I'm cdb5341mb, and I need help. I'm trying to add the numbers in a single cell and don't know if there is a formula for it. I tried everything I could think of but nothing works.

0 5 0 05
0 5 0 16
0 5 0 27
0 5 0 38
0 5 0 49
0 5 0 510
0 5 0 611
0 5 0 712
0 5 0 813
0 5 0 914
0 5 1 06
0 5 1 17
0 5 1 28
0 5 1 39
0 5 1 410

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>
It seems to be easy but its not working and to do this in long hand is very time consuming .

If anyone can help I would be grateful.
Thank you in advance
cdb5341mb
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Although this is possible with a formula (assuming each cell will always have 4 digits), a UDF would be more flexible:

Code:
Function Add_Cell(c As Range)

Dim i As Long


For i = 1 To Len(c)
    Add_Cell = Add_Cell + Mid(c, i, 1) + 0
Next i


End Function

Sheet1

*AB
105005
205016
305027
405038
505049
6050510
7050611
8050712
9050813
10050914
1105106
1205117
1305128
1405139
15051410

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:64px;"><col style="width:64px;"></colgroup><tbody>
</tbody>

Spreadsheet Formulas
CellFormula
B1=Add_Cell(A1)
B2=Add_Cell(A2)
B3=Add_Cell(A3)
B4=Add_Cell(A4)
B5=Add_Cell(A5)
B6=Add_Cell(A6)
B7=Add_Cell(A7)
B8=Add_Cell(A8)
B9=Add_Cell(A9)
B10=Add_Cell(A10)
B11=Add_Cell(A11)
B12=Add_Cell(A12)
B13=Add_Cell(A13)
B14=Add_Cell(A14)
B15=Add_Cell(A15)

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Upvote 0
The way you posted your "numbers" they appear to be digits with space delimiters. If that's true then here's an alternative UDF for you.

Excel Workbook
AB
10 5 0 05
20 5 0 16
30 5 0 27
40 5 0 38
50 5 0 49
60 5 0 510
70 5 0 611
80 5 0 712
90 5 0 813
100 5 0 914
110 5 1 06
120 5 1 17
130 5 1 28
140 5 1 39
150 5 1 410
Sheet2


Code:
Function AddCellNums(S As String)
For i = 0 To UBound(Split(S, " "))
    AddCellNums = AddCellNums + Val(Split(S, " ")(i))
Next i
End Function
 
Upvote 0
Hi,

I'd do it with a formula.


=SUMPRODUCT(--MID(SUBSTITUTE(A1," ",""),ROW($A$1:INDEX($A:$A,LEN(SUBSTITUTE(A1," ","")),1)),1))
 
Upvote 0
If there will always be 4 digits, separated by spaces...
try this:
Code:
=SUMPRODUCT(--MID(A1,{1,3,5,7},1))
If the length may vary, use this:
Code:
=SUMPRODUCT(--MID(A1,(ROW(INDIRECT("1:"&CEILING(LEN(A1)/2,1)))-1)*2+1,1))

Is that something you can work with?
 
Upvote 0
The way you posted your "numbers" they appear to be digits with space delimiters. If that's true then here's an alternative UDF for you.
Code:
Function AddCellNums(S As String)
For i = 0 To UBound(Split(S, " "))
    AddCellNums = AddCellNums + Val(Split(S, " ")(i))
Next i
End Function
Here is another way to write such a function, given your assumption (it's a one-liner)...
Code:
Function DigitSum(S As String) As Long
  DigitSum = Evaluate(Replace(S, " ", "+"))
End Function
 
Upvote 0
The way you posted your "numbers" they appear to be digits with space delimiters. If that's true then here's an alternative UDF for you.
Code:
Function AddCellNums(S As String)
For i = 0 To UBound(Split(S, " "))
    AddCellNums = AddCellNums + Val(Split(S, " ")(i))
Next i
End Function
Here is another way to write such a function, given your assumption (it's a one-liner)...
Code:
Function DigitSum(S As String) As Long
  DigitSum = Evaluate(Replace(S, " ", "+"))
End Function
And this function (another one-liner) will work whether the digits have spaces between them or not...
Code:
Function DigitSum(S As String) As Long
  DigitSum = Evaluate(Replace(StrConv(S, vbUnicode), Chr(0), "+") & "0")
End Function
 
Upvote 0
Thanks to ALL of you that helped me solve this problem. IT'S WORKING.
The CODE and FORMULAS, all seem to do the job. Again thank you (niimack, JoeM, MikeLH, Ron Coderre and Rick Rothstein)
You guys are GREAT
Thank you cdb5341mb
 
Upvote 0

Forum statistics

Threads
1,214,635
Messages
6,120,660
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top