Adding numbers in between slashes

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,434
Hi Guys,

Is there a formula that can add numbers separated by slashes in a cell? So for example I have 0/2/1/0/3, the desired result is 6.

Thanks
Asad
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
If you are ok using a custom function...

Code:
Function Eval(Ref As String)

Dim sbs As String

sbs = WorksheetFunction.Substitute(Ref, "/", "+")
Eval = Evaluate(sbs)

End Function
 
Upvote 0
That's wonderful. That will be one option. But I prefer to do it with a formula. So I will wait for another guru to give another answer before I use this one.
 
Upvote 0
I am thinking of changing that VB script to formula. Something like:
Code:
=SUM(SUBSTITUTE(A1,"/",","))
with ctrl+shift+enter
It gives an error.
But the solution must along the similar lines.
 
Upvote 0
Try

=SUMPRODUCT(--MID(SUBSTITUTE(A1,"/",""),ROW(INDEX(A:A,1):INDEX(A:A,LEN(SUBSTITUTE(A1,"/","")))),1))
 
Upvote 0
=SUMPRODUCT(--MID(SUBSTITUTE(A1,"/",""),ROW(INDEX(A:A,1):INDEX(A:A,LEN(SUBSTITUTE(A1,"/","")))),1))
This wouldn't work if there was a double digit number, will it? Like 0/11/2/0/3, the answer should be 16 but the formula gives 7.
 
Upvote 0
In this case, an UDF would be, probably, the easiest approach:
Code:
Function SumNum(s As String) As Double
    SumNum = Evaluate(Replace(s, "/", "+"))
End Function
 
Upvote 0

Excel 2010
ABC
10/2/1/0/366
20/21/0/32424
3
3d
Cell Formulas
RangeFormula
B1=Calc
C1=Eval(A1)
Named Ranges
NameRefers ToCells
Calc=EVALUATE(SUBSTITUTE(!B3,"/","+"))


Use a Named range
Select cell B1
With Name Manager
New I used the name "Calc".
Refers to: =EVALUATE(SUBSTITUTE(!A1,"/","+"))

This obviously is equivalent to the UDF Eval.
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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