add to existing value

fatdog

New Member
Joined
Mar 2, 2011
Messages
4
I need to allow people to enter values that are then added to a single cell to maintain a running total, but i want to keep it as simple as possible for the user so they don't need to add values manually to avoid potential user error

a simplified example, if 10 was in a cell already, one person may need to submit a value of 4, another user 6, and at the end of the day i would expect to see a single cell containing the number 20

if a1 contains a value, is it possible to have it setup so someone can enter a value into b1 then that value will be added to the number currently in a1 and then b1 is then cleared ready for the next person

or alternatively could someone enter a value into cell a1 directly and it be added to the current value rather than clearing and replacing whats already in there

any tips would be greatly appreciated
 
sorry didn't think that was relevant
If you need code altered to suit your particular circumstances and are not able to do it yourself, then your particular circumstanced are definitely relevant. ;)


There would be two changes to my code, marked red below

Rich (BB code):
Set Bchanged = Intersect(Target, Range("K14:K25"))


With Bcell.Offset(, -2)
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
or alternatively could someone enter a value into cell a1 directly and it be added to the current value rather than clearing and replacing whats already in there

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range, x, y
Set cell = Intersect(Target, [A1])
If cell Is Nothing Then Exit Sub
With Application
    .EnableEvents = False
    x = cell
    .Undo
    y = cell
    On Error Resume Next
    cell = x + y
    On Error GoTo 0
    .EnableEvents = True
End With
End Sub
 
Last edited:
Upvote 0
@footoo
Are you answering the current question or the 5 year old one? :)
 
Upvote 0
Starting with your original code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "B1" Then
Application.EnableEvents = False
Range("A1").Value = Range("A1").Value + Target.Value
Target.ClearContents
Application.EnableEvents = True
End If
End Sub

What lines exactly do I change? Sorry, like I said I'm not really good with Macros
 
Last edited:
Upvote 0
If you need code altered to suit your particular circumstances and are not able to do it yourself, then your particular circumstanced are definitely relevant. ;)


There would be two changes to my code, marked red below

Rich (BB code):
Set Bchanged = Intersect(Target, Range("K14:K25"))


With Bcell.Offset(, -2)

Sorry I know this is an old post, but I have a need for this again and don't have my original document. I see your 2 code changes, but I'm not sure where to put that code, or what exactly to change in your code here:
This was to do this on a range of cells in a table i.e. whenever I change any cell in column Table21[Amount] it will add it to the total in that same cell "or adjacent cell"

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "B1" Then
Application.EnableEvents = False
Range("A1").Value = Range("A1").Value + Target.Value
Target.ClearContents
Application.EnableEvents = True
End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,561
Messages
6,125,533
Members
449,236
Latest member
Afua

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