I currently have this code for my worksheet:
Private Sub Worksheet_Change(ByVal Target As Range)
' ensure events are always enabled when we exit this Sub, even if we have an error
On Error GoTo errExit
Application.EnableEvents = False
Dim SpotRate As Double
SpotRate = Me.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
errExit:
Application.EnableEvents = True
End Sub
There is a pair a dropdown in cell C2 that contains information for the spot rate.
When I input the values into C3 or E3 the code works as required. However, if I change the value in cell C2 (which changes the spot rate in H2), these values don't automatically update in C3 or E3. Is there a way I can change this so that the value in C3 is held constant but E3 is automatically updated according to the new spot rate? Thanks.
You have blocks of code that perform some actions when the Target (range that changed, triggering the Worksheet_Change event) address is "$C$3" and "$E$3".
You need an equivalent block that will perform the calculation if Target.Address = "$H$2".
Assuming my understanding of what you're trying to achieve is correct, this should work for you:
EDIT: Sorry, misuderstood the question at first, corrected my comment to include the right solution.