Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
ahemani
 
Posts: n/a
Default 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

  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

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



  #3   Report Post  
Gord Dibben
 
Posts: n/a
Default

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Make Alignment options under format cells available as shortcut dforrest Excel Discussion (Misc queries) 1 July 14th 05 10:58 PM
Help with macro looping and color query function kevinm Excel Discussion (Misc queries) 10 May 26th 05 01:25 AM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM


All times are GMT +1. The time now is 06:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"