I am trying to make it so if information is entered into C3
, it outputs C3*H2
in E3
, and if information is entered into E3
, it outputs E3/H2
in C3
. My code works perfectly fine, but excel crashes when I change the inputted number and the macro runs.
This is my code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim SpotRate As Double
Dim srcSheet As Worksheet
Set srcSheet = ThisWorkbook.Worksheets("Input Data")
SpotRate = srcSheet.Range("H2").Value
If Target.Address = "$C$3" Then
If Target.Value <> "" Then
Range("E3").Value = Target.Value * SpotRate
Else
Range("E3").ClearContents
End If
ElseIf Target.Address = "$E$3" Then
If Target.Value <> "" Then
Range("C3").Value = Target.Value / SpotRate
Else
Range("C3").ClearContents
End If
End If
End Sub
Note: Excel doesn't crash immediately, so I am able to edit it. It only crashes when I change the numbers in C3
or E3
.