Cumulative value in a single cell

  • Thread starter Thread starter Shah Alam
  • Start date Start date
S

Shah Alam

Dear xls xperts,
I want the solution below.

cell A
Cell B
Cell C
Suppose, i put 50 in cell B, Cell A will take it and add the number
frequently. again if I delete or put another 50 on cell B, even then cell A
will show me 100(50+50) whereas Cell C will only minus the number that Cell
B helps Cell A to add. thanks

Shah Alam
 
I don't understand what you want to do with cell C. You can accumulate values
entered into cell B in cell A using an event macro like the following:

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

In this example, A1 is cell A and B1 is cell B. Right-click on the name tab
of the sheet where you want this to work, then select View Code. The Visual
Basic Editor (VBE) is displayed. Paste the code above in the blank window.
Save the workbook, then close the VBE and return to Excel.

There are pitfalls to using a cell as an accumulator. Here is link to more
information:
http://www.mcgimpsey.com/excel/accumulator.html

If you are new to macros, this link to Jon Peltier's site may be helpful:
http://peltiertech.com/WordPress/2008/03/09/how-to-use-someone-elses-macro/

Hope this helps,

Hutch
 
Back
Top