Sum variable cell in another cell

Luigi802

Board Regular
Joined
Oct 16, 2014
Messages
80
So I want to be able to constantly change a number in let's say A1 and have B1 constantly adding up what I type in A1.
For example; I type 3 in A1, B1 returns 3, then I change the number in A1 to 1, then in B1 I want to return 4, change A1 to 6, B1 then returns 10 and so on.
I'm thinking I may have to use VBA code, I'm a beginner with VBA so a formula would be best; however, I'm willing to use VBA
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "A1" Then
      Range("B1").Value = Range("B1").Value + Target.Value
   End If
End Sub
Right click the tab you want this to work on > select "View Code" > Paste the above into the window that opens up.
 
Upvote 0
Right click the tab for the sheet that you want this to happen on. Click on View Code. Paste the following code in the white area.
Hit Alt-q
When you save your workbook, be sure and save it as type .xlsm

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim d As Range
Set d = Intersect(Target, Range("B1"))
If d Is Nothing Then Exit Sub
Application.EnableEvents = False
If IsNumeric(d) Then Range("A1") = Range("A1") + d
Application.EnableEvents = True
End Sub
 
Upvote 0
Right click the tab for the sheet that you want this to happen on. Click on View Code. Paste the following code in the white area.
Hit Alt-q
When you save your workbook, be sure and save it as type .xlsm

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim d As Range
Set d = Intersect(Target, Range("B1"))
If d Is Nothing Then Exit Sub
Application.EnableEvents = False
If IsNumeric(d) Then Range("A1") = Range("A1") + d
Application.EnableEvents = True
End Sub


Awesome! that works, but can I do it on a range? like G9:G63 will be the result of G9:G63
 
Upvote 0
Yes. That's not what you asked in your original question though. I'm assuming you want to enter your data in F9:F63 because you didn't specify.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range
Set d = Intersect(Target, Range("F9:F63"))
If d Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In d
    If IsNumeric(c) Then c.Offset(, 1) = c.Offset(, 1) + c
Next
Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0
Yes. That's not what you asked in your original question though. I'm assuming you want to enter your data in F9:F63 because you didn't specify.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range
Set d = Intersect(Target, Range("F9:F63"))
If d Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In d
    If IsNumeric(c) Then c.Offset(, 1) = c.Offset(, 1) + c
Next
Application.EnableEvents = True
End Sub

No I apologize, I didn't specify, I thought it'd be an easy change that I could do. I learn best sometimes by playing around with existing code lol
Thank you though that worked perfectly!
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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