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.you can accomplished that using vba.
Go to TOOLSgt;MACROgt;Visual 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'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = quot;A1:B1quot;
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 quot;$A$1quot;
.Offset(0, 2).Value = .Offset(0, 2).Value - .Value
Case quot;$B$1quot;
.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)
quot;chris1bcooquot; gt; wrote in message
...
gt; Let's say I have 3 columns.
gt; I want to deduct from cell C1 when # is put in cell A1 and zero out A1
after
gt; the calculation.
gt; Also I want to add to cell C1 when # is put in cell B1 and zero out B1
after
gt; the calculation.
gt;
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 = quot;A2,D2quot;
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 quot;$A$2quot;
.Offset(0, 2).Value = .Offset(0, 2).Value - .Value
Case quot;$D$2quot;
.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)
quot;Bob Phillipsquot; gt; wrote in message
...
gt; '-----------------------------------------------------------------
gt; Private Sub Worksheet_Change(ByVal Target As Range)
gt; '-----------------------------------------------------------------
gt; Const WS_RANGE As String = quot;A1:B1quot;
gt;
gt; On Error GoTo ws_exit:
gt; Application.EnableEvents = False
gt; If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
gt; With Target
gt; Select Case .Address
gt; Case quot;$A$1quot;
gt; .Offset(0, 2).Value = .Offset(0, 2).Value - .Value
gt; Case quot;$B$1quot;
gt; .Offset(0, 1).Value = .Offset(0, 1).Value .Value
gt; End Select
gt; .Value = 0
gt; End With
gt; End If
gt;
gt; ws_exit:
gt; Application.EnableEvents = True
gt; End Sub
gt;
gt; 'This is worksheet event code, which means that it needs to be
gt; 'placed in the appropriate worksheet code module, not a standard
gt; 'code module. To do this, right-click on the sheet tab, select
gt; 'the View Code option from the menu, and paste the code in.
gt;
gt;
gt;
gt;
gt;
gt; --
gt; HTH
gt;
gt; Bob Phillips
gt;
gt; (remove nothere from email address if mailing direct)
gt;
gt; quot;chris1bcooquot; gt; wrote in message
gt; ...
gt; gt; Let's say I have 3 columns.
gt; gt; I want to deduct from cell C1 when # is put in cell A1 and zero out A1
gt; after
gt; gt; the calculation.
gt; gt; Also I want to add to cell C1 when # is put in cell B1 and zero out B1
gt; after
gt; gt; the calculation.
gt; gt;
gt;
gt;
- Sep 29 Fri 2006 20:09
making a cell zero out after calculation
close
全站熱搜
留言列表
發表留言