One way:
Put this in your worksheet code module (right-click the worksheet tab
and choose View Code):
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const cdScale As Double = 2
With Target
If Not Intersect(Range("A1:A2"), Cells) Is Nothing Then
On Error Resume Next
Application.EnableEvents = False
If .Address = "A1" Then
.Offset(1, 0).Value = .Value * cdScale
Else
.Offset(-1, 0).Value = .Value / cdScale
End If
Application.EnableEvents = True
End If
End With
End Sub
In article ,
James Lee <James
wrote:
For example, if Y = X*2
X is in cell A1
Y is in cell A2
we usually write "= A1*2" in A2 " to find out the Y value when we know X
or we could write "= A2/2" in A1 to calculate X when we have Y
but these functions work one direction only
what if I sometimes know X and some other times know Y
How do I write a two-way function where I can put in known X value or Y
value to calculate for the other unknown value (Y or X)