ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Noob help (https://www.excelbanter.com/excel-worksheet-functions/16335-noob-help.html)

Patrick

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.

Bob Phillips

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.




patrick

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.





Bob Phillips

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.








All times are GMT +1. The time now is 04:51 PM.

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