Adding multiple numbers contained within a single cell

babycody

Well-known Member
Joined
Jul 8, 2003
Messages
1,395
Is it possible to have multiple numbers i.e. 2,43,8 in a single cell, and show the sum of these numbers in another cell? Also is it possible to add characters IIII together to get 4? Thanks ahead for any help on this matter.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
For the first question put this function in a General module:

Code:
Function Eval(Ref)
    Eval = Evaluate(CStr(Ref))
End Function

Then you can use:

=Eval(SUBSTITUTE(A1,",","+"))

where A1 contains the list of comma separated numbers.
 
Upvote 0
Code:
Also is it possible to add characters IIII together to get 4?

You really can't add "I"s since they are chacacters, not numbers, but you can count them using the LEN function:
=LEN(A1)
 
Upvote 0
OK, one more question on the Eval formula. When the cell A1 is blank the formula returns ####. How can I clean this up?
 
Upvote 0
Try this modification to Andrew's code:

Code:
Function Eval(Ref)
    If Len(Ref) > 0 Then Eval = Evaluate(CStr(Ref))
End Function
 
Upvote 0
Not quite the problem I have. The LEN() function is working properly. It is used in a completely seperate column. The VBA code is where I am having the problem. Is there something like an error trap that I can use on the formulas? I really just need the Eval function to return nothing if the cell to the left is blank.
 
Upvote 0
jmiskey said:
Try this modification to Andrew's code:

Code:
Function Eval(Ref)
    If Len(Ref) > 0 Then Eval = Evaluate(CStr(Ref))
End Function

Or:

=IF(LEN(A1),Eval(SUBSTITUTE(A1,",","+")),"")
 
Upvote 0
<font face=Courier New><SPAN style="color:#00007F">Function</SPAN> eval(ref)
<SPAN style="color:#00007F">If</SPAN> (Len(ref)) <SPAN style="color:#00007F">Then</SPAN>
    eval = Evaluate(Application.WorksheetFunction.Substitute(ref, ",", "+"))
<SPAN style="color:#00007F">Else</SPAN>
    eval = vbNullString
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN></FONT>
 
Upvote 0
Thanks Andrew Poulsom. The adjustment to the formula itself you gave me worked very nicely. Thanks for everyones input on this.
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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