Using VBA how do I detect when any value in a worksheet changes?

前端 未结 2 908
温柔的废话
温柔的废话 2021-01-24 05:00

I have a worksheet that contains a few columns with hundreds of values. I want cell A1 to say \"Value Changed\" as soon as any value changes in the worksheet. I tried to make so

2条回答
  •  臣服心动
    2021-01-24 05:43

    You can "temporarily UnDo" to retrieve the original value:

    Private Sub Worksheet_Change(ByVal Target As Range)
       Dim Where As String, Oldvalue As Variant, NewValue As Variant
       Application.EnableEvents = False
          Where = Target.Address
          NewValue = Target.Value
          Application.Undo
          Oldvalue = Target.Value
          Target.Value = NewValue
       Application.EnableEvents = True
    
       MsgBox Where & vbCrLf & Oldvalue & vbCrLf & NewValue
    End Sub
    

    This is only good for single cells.

提交回复
热议问题