two-variable calculations continued ...

B

Bob Phillips

Gary is suggesting not using a macro, but using code like this

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
Me.Cells(.Row, "C").Value = Me.Cells(.Row, "A") + _
Me.Cells(.Row, "B").Value
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

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

Bernie Deitrick

fredonic,

You need to do a lot for that, and it must be equation specific: Copy the code below, right click
on the sheet tab, select "View Code", and paste the code in the window that appears.

HTH,
Bernie
MS Excel MVP

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("A1:C1")) Is Nothing Then Exit Sub
If Target.Value = "" Then Exit Sub
If Application.WorksheetFunction.CountBlank(Range("A1:C1")) <> 1 Then Exit Sub

Application.EnableEvents = False
If Range("A1").Value = "" Then
Range("A1").Value = Range("C1").Value - Range("B1").Value
End If
If Range("B1").Value = "" Then
Range("B1").Value = Range("C1").Value - Range("A1").Value
End If
If Range("C1").Value = "" Then
Range("C1").Value = Range("A1").Value + Range("B1").Value
End If
Application.EnableEvents = True
End Sub
 
Top