我有一个需要在单元格值更改时运行的宏。
这就是我所拥有的。这不起作用,因为当我更改单元格的值然后按Enter键或单击其他单元格时,宏从我移动到的单元格中获取值,而不是从我更改了值的单元格中取值
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Me.Range("B3:V34")) Is Nothing Then Exit Sub
Application.EnableEvents = False 'to prevent endless loop
On Error GoTo Finalize 'to re-enable the events
MsgBox (Target.Address)
'prints the cell address whose value I changed before I clicked on some other cell
MsgBox (ActiveCell.Address)
'prints the cell address of the new cell where I have moved to
ActiveCell.Range(Target.Address).Activate
'This is me trying to move the active cell to the cell whose value I changed
'But this doesn't work. The activeCell moves to some random cell
'I wanna run a macro here which takes activeCell address and value as input
Finalize:
Application.EnableEvents = True
End Sub