Adding the values in a cell...

MoltenPoo

New Member
Joined
Apr 24, 2002
Messages
6
I am trying to write a formula to add the number values in a cell. For example If I populate cell (A1) with the number 12345 I would like to see the sum of those numbers in cell (B1). I can pull this off using LEN and MID.

However, if column A is populated with number values of varying lengths my formula breaks. I DO NOT want to do this using VBA. Any ideas?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
{=SUM(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)+0)}

Note: This is an array formula which is entered using the Control+Shift+Enter key combination.
This message was edited by Mark W. on 2002-04-25 16:04
 
Upvote 0
Hi,

Array enter
=SUM(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)+0)

Must be entered with Ctrl-Shift-Enter

HTH,
Jay

EDIT: Obviously Mark was quicker on the draw here with the same answer. He is one fast gunslinger. This post isn't big enough for the two of us, so I will slink away now. :)
This message was edited by Jay Petrulis on 2002-04-25 16:07
 
Upvote 0
Hi,

The above formulas fail if the cell is:

a.< 0
b. blank
c. non-integer
d. contain any non-numeric characters

The following corrects the first three (assuming the decimal separator is a .)

{=IF(LEN(A1),SUM(MID(ABS(SUBSTITUTE(A1,".","")),ROW(INDIRECT("1:"&LEN(ABS(SUBSTITUTE(A1,".",""))))),1)+0),0)}

again, array-entered.

Obviously this is overkill, so please take this with a grain of salt, as the primary formula works fine.

Bye,
Jay


EDIT: Or, to correct all four
=IF(ISNUMBER(A1),SUM(MID(ABS(SUBSTITUTE(A1,".","")),ROW(INDIRECT("1:"&LEN(ABS(SUBSTITUTE(A1,".",""))))),1)+0),0)
This message was edited by Jay Petrulis on 2002-04-25 17:08
 
Upvote 0
On 2002-04-25 17:05, Jay Petrulis wrote:
Hi,

The above formulas fail if the cell is:

a.< 0
b. blank
c. non-integer
d. contain any non-numeric characters

The following corrects the first three (assuming the decimal separator is a .)

...
This message was edited by Jay Petrulis on 2002-04-25 17:08

Or, you could setup Data Validation on A1.
 
Upvote 0
On 2002-04-25 17:41, Mark W. wrote:
On 2002-04-25 17:05, Jay Petrulis wrote:
Hi,

The above formulas fail if the cell is:

a.< 0
b. blank
c. non-integer
d. contain any non-numeric characters

The following corrects the first three (assuming the decimal separator is a .)

...
This message was edited by Jay Petrulis on 2002-04-25 17:08

Or, you could setup Data Validation on A1.

Now why would anybody want to do something simple and painless when they can do something that is nearly impossible to decipher? Who want easy when you can have a Rube Goldberg solution. :biggrin:

I didn't even think of the obvious. Way cool.

Bye,
Jay
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,140
Members
448,551
Latest member
Sienna de Souza

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