Update and remember previous values ?

  • Thread starter Thread starter Christian K
  • Start date Start date
C

Christian K

Hi,

I would like to be able to input a number in (for
example) column A1, and the result should be shown in B1,
and if I once again enter a number in A1, the previous
number/sum should be updated/added in B1.

For instance; if I enter 100 in A1, the result in B1
should be 100, and then if I later on enter 200 in A1,
the result in B1 should be 300.

How do I accomplish the above?

Thanks!

/Chris
 
Christian

copy and paste the following code into the Worksheet Class Module for the
worksheet where you want this to happen

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
If Range("A1").HasFormula Then Exit Sub
If Not IsNumeric(Target.Value) Then Exit Sub
Application.EnableEvents = False
Range("B1").Value = Range("B1").Value + Range("A1").Value
Application.EnableEvents = True
End Sub

Regards

Trevor
 
Christian,

Put this code in the worksheet code module

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ws_exit
If Target.Address = "$A$1" Then
Range("$B$1").Value = Range("$B$1").Value + Target.Value
End If

ws_exit:
Application.EnableEvents = True
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top