Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
chris1bcoo
 
Posts: n/a
Default making a cell zero out after calculation

Lets say I have 3 columns.
I want to deduct from cell C1 when # is put in cell A1 and zero out A1 after
the calculation.
Also I want to add to cell C1 when # is put in cell B1 and zero out B1 after
the calculation.

  #2   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default making a cell zero out after calculation

you can accomplished that using vba.

Go to TOOLSMACROVisual Basic Editor

then click on the sheet and paste this code in the code area.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells(1, 3).Value = Cells(1, 3).Value + Cells(1, 1).Value
Cells(1, 3).Value = Cells(1, 3).Value - Cells(1, 2).Value
Cells(1, 1).Value = 0
Cells(1, 2).Value = 0
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default making a cell zero out after calculation

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "A1:B1"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Address
Case "$A$1"
.Offset(0, 2).Value = .Offset(0, 2).Value - .Value
Case "$B$1"
.Offset(0, 1).Value = .Offset(0, 1).Value + .Value
End Select
.Value = 0
End With
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

Bob Phillips

(remove nothere from email address if mailing direct)

"chris1bcoo" wrote in message
...
Let's say I have 3 columns.
I want to deduct from cell C1 when # is put in cell A1 and zero out A1

after
the calculation.
Also I want to add to cell C1 when # is put in cell B1 and zero out B1

after
the calculation.



  #4   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default making a cell zero out after calculation

Re your private email, you need to adjust the cell references to your data

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "A2,D2"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Address
Case "$A$2"
.Offset(0, 2).Value = .Offset(0, 2).Value - .Value
Case "$D$2"
.Offset(0, -1).Value = .Offset(0, -1).Value + .Value
End Select
.Value = 0
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"Bob Phillips" wrote in message
...
'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "A1:B1"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Address
Case "$A$1"
.Offset(0, 2).Value = .Offset(0, 2).Value - .Value
Case "$B$1"
.Offset(0, 1).Value = .Offset(0, 1).Value + .Value
End Select
.Value = 0
End With
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

Bob Phillips

(remove nothere from email address if mailing direct)

"chris1bcoo" wrote in message
...
Let's say I have 3 columns.
I want to deduct from cell C1 when # is put in cell A1 and zero out A1

after
the calculation.
Also I want to add to cell C1 when # is put in cell B1 and zero out B1

after
the calculation.





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
Making a particular cell or column required Ronco Excel Discussion (Misc queries) 0 April 26th 06 09:01 PM
Instead of a negative number, I'd like to show zero... Dr. Darrell Excel Worksheet Functions 6 December 7th 05 08:21 PM
copying cell names Al Excel Discussion (Misc queries) 12 August 11th 05 03:01 PM
cell color index comparison MINAL ZUNKE New Users to Excel 1 June 30th 05 07:11 AM
overtime calculation in 1 cell garpavco Excel Worksheet Functions 1 January 5th 05 10:55 PM


All times are GMT +1. The time now is 12:48 PM.

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"