How do I add/count numbers in the same cell in excel worksheet?

B

Brecken

How do I create a function or formula in acell to perform this operation?
(i.e if I have the number 127 in a cell and want to to enter 50 into the same
cell so that I get a sum of 177 in the same cell, how do I do this, rather
than adding the 2 numbers in my head, and manually entering 177?) I am doing
this for purposes of a budget and entering receipts. If the amount I've
spent on groceries is $127 up to the present time, and I want to add an
additional grocery receipt of $50, I want to be able to have the cell add the
new entry, rather than adding the 50 in my head and enter $177. Thanks!
 
S

Scott

Probably the wisest way to use one cell to do this would be to put the
following in the cell:

=127

When you get a $50 receipt, change it to:

=127+50

When you get another receipt, say 34.95:

=127+50+34.95

The reason to do it this way is so that if you happen to make a mistake
when entering the value, you don't lose your previous data.

Scott
 
B

Brecken

Isn't there another way that's easier, though, so I can just add a number and
have it automatically added to the existing number in the same cell? Thanks.
 
J

Joerg

For a start, put following code into a module. When you run the
AddValueOnEnter macro, whatever value you enter will be added to the
existing value (your existing '127' will become '=127+50', so that you can
still trace your inputs). Run ResetEnter when you want to reset the ENTER
key to normal behaviour.

Cheers,
Joerg Mochikun


Public PresentValue As String

Sub AddValueOnEnter()
Application.OnKey "{ENTER}", "AddValue"
End Sub

Sub ResetEnter()
Application.OnKey "{ENTER}", ""
End Sub

Sub Addvalue()
On Error Resume Next
If Left(PresentValue, 1) <> "=" Then PresentValue = "=" & PresentValue
ActiveCell.Formula = PresentValue & "+" & ActiveCell.Formula
PresentValue = ActiveCell.Formula
End Sub
 
D

David Biddulph

Put your 50 in a spare cell, Copy, go to the cell with your 127, Edit/ Paste
Special/ Add
 
G

Gord Dibben

Brecken

Are you sure you want to do this?

Think about it after reading the following.

You can have a cumulative total in a cell if you have a
separate source cell for adding a new total to the original.

Use at your own risk. I am Posting this just to show you how it can
be done, not as a good solution. You would be much better off to
have another column so you can keep track of past entries.

Goes like this: =IF(CELL("address")="$C$4",C4+D4,D4)

Enter this in cell D4 and then in Tools>Options>Calculation check
Iterations and set to 1.

Now when you change the number in C4, D4 will accumulate.

Note 1. If C4 is selected and a calculation takes place anywhere in
the Application D4 will update even if no new number is entered in
C4. NOT GOOD.

Note 2. This operation is not recommended because you will have no
"paper trail" to follow. Any mistake in entering a new number in C4
cannot be corrected. NOT GOOD.

To clear out the accumulated total in D4 and start over, select D4
and Edit>Enter.

Check out Laurent Longre's MoreFunc.xla. Has a Function RECALL
which does what you want without the re-calculation problem, but
again there is no "paper trail" for back-checking in case of errors
in data input.

http://longre.free.fr/english/func_cats.htm

Also see John McGimpsey's site for VBA method and the same caveats as above.

http://www.mcgimpsey.com/excel/accumulator.html


Gord Dibben Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top