VBA trigger macro on cell value change
event-handling, excel, vba
Solution
Could you try something like this? Change the formula to `=D3AlertOnChange(B3*C3)`.
Private D3OldVal As Variant
Public Function D3AlertOnChange(val)
If val <> D3OldVal Then MsgBox "Value changed!"
D3OldVal = val
D3AlertOnChange = val
End Function
Problem
This should be simple. When the value of a cell changes I want to trigger some VBA code. The cell (D3) is a calculation from two other cells `=B3*C3`. I have attempted 2 approaches: ``` Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 4 And Target.Row = 3 Then MsgBox "There was a change in cell D3" End If End Sub ``` Since the cell is a calculation this is not triggered when the value changes, because the calculation remains the same. I also tried: ``` Private Sub Worksheet_Calculate() MsgBox "There was a calculation" End Sub ``` But I have multiple calculations on the sheet and it triggers multiple times. Is there a way I can identify which calculation changed on the calculation event? Or is there another way I can track when D3 changes?