ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   macro for auto sum (https://www.excelbanter.com/new-users-excel/37461-macro-auto-sum.html)

ahemani

macro for auto sum
 
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


Bob Phillips

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)


"ahemani" wrote in message
...
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




Gord Dibben

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

On Wed, 27 Jul 2005 22:09:01 -0700, "ahemani"
wrote:

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




All times are GMT +1. The time now is 12:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com