macro for auto sum

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am fairly new to macros in general. Does anyone have an existing macro
that I can use which will auto sum the existing value in a cell with a new
value added to it......i.e. if cell B10 has a value in it of 55 and I type in
5 into cell B10 it will auto sum and leave 60 as the new cell contents ?
the actual code would really help...or just steps to do this.
thanks
 
Option Explicit

Private prevValue

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
If .Address = "$B$6" Then
.Value = prevValue + .Value
End If
prevValue = .Value
End With

ws_exit:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Target
If .Address = "$B$6" Then
prevValue = .Value
End If
End With
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Can be done as Bob points out, but do you really want to do this?

Where is your "paper trail" so's you can keep track of entries?

What do you do when someone enters 9 instead of 10?

If you want to have an accumulator cell.....lotsa luck.


Gord Dibben Excel MVP
 
Back
Top