#1   Report Post  
Patrick
 
Posts: n/a
Default Noob help

I want to format a cell to keep a total. We will call this cell T. I want it
to keep a total from cell A which when I put a number it will add to the
total in cell T. I also want cell T to keep a total from cell S so when I put
a number in S then it will subtract from the total. Ok I know how to do that.
My question is when I put a number in either cell S or A I want to be able to
see that entry but then if I want to add another number to it the total adds
that number also.
Here is an example T=0, I put 20 in A. Now T shows 20 and A also shows 20.
Now I want to put 20 in A again. I want for T to show 40 now and A to show
20. When I do this it does not change the total.
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Address = "$T$1" Then
Me.Range("A1").Value = Me.Range("A1").Value + Target.Value
ElseIf Target.Address = "$S$1" Then
Me.Range("A1").Value = Me.Range("A1").Value - Target.Value
End If

ws_exit:
Application.EnableEvents = True
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)


"Patrick" wrote in message
...
I want to format a cell to keep a total. We will call this cell T. I want

it
to keep a total from cell A which when I put a number it will add to the
total in cell T. I also want cell T to keep a total from cell S so when I

put
a number in S then it will subtract from the total. Ok I know how to do

that.
My question is when I put a number in either cell S or A I want to be able

to
see that entry but then if I want to add another number to it the total

adds
that number also.
Here is an example T=0, I put 20 in A. Now T shows 20 and A also shows 20.
Now I want to put 20 in A again. I want for T to show 40 now and A to show
20. When I do this it does not change the total.



  #3   Report Post  
patrick
 
Posts: n/a
Default

What part of this exaclty am I supposed to paste.

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Address = "$T$1" Then
Me.Range("A1").Value = Me.Range("A1").Value + Target.Value
ElseIf Target.Address = "$S$1" Then
Me.Range("A1").Value = Me.Range("A1").Value - Target.Value
End If

ws_exit:
Application.EnableEvents = True
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)


"Patrick" wrote in message
...
I want to format a cell to keep a total. We will call this cell T. I want

it
to keep a total from cell A which when I put a number it will add to the
total in cell T. I also want cell T to keep a total from cell S so when I

put
a number in S then it will subtract from the total. Ok I know how to do

that.
My question is when I put a number in either cell S or A I want to be able

to
see that entry but then if I want to add another number to it the total

adds
that number also.
Here is an example T=0, I put 20 in A. Now T shows 20 and A also shows 20.
Now I want to put 20 in A again. I want for T to show 40 now and A to show
20. When I do this it does not change the total.




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

The code bit. You could paste it all as the rest is comments.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"patrick" wrote in message
...
What part of this exaclty am I supposed to paste.

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Address = "$T$1" Then
Me.Range("A1").Value = Me.Range("A1").Value + Target.Value
ElseIf Target.Address = "$S$1" Then
Me.Range("A1").Value = Me.Range("A1").Value - Target.Value
End If

ws_exit:
Application.EnableEvents = True
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)


"Patrick" wrote in message
...
I want to format a cell to keep a total. We will call this cell T. I

want
it
to keep a total from cell A which when I put a number it will add to

the
total in cell T. I also want cell T to keep a total from cell S so

when I
put
a number in S then it will subtract from the total. Ok I know how to

do
that.
My question is when I put a number in either cell S or A I want to be

able
to
see that entry but then if I want to add another number to it the

total
adds
that number also.
Here is an example T=0, I put 20 in A. Now T shows 20 and A also shows

20.
Now I want to put 20 in A again. I want for T to show 40 now and A to

show
20. When I do this it does not change the total.






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



All times are GMT +1. The time now is 07:26 AM.

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

About Us

"It's about Microsoft Excel"