我有一个工作表,记录使用对单元格所做的更改。它如下
Public OldVal As String
Public NewVal As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
OldVal = Target.Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LDate As String
If Target.Cells.Count > 1 Then Exit Sub
NewVal = Target.Value
Sheets("corrections").Cells(Rows.Count, "A").End(xlUp)(2).Value = Now & "_Sheet " & ActiveSheet.Name & " Cell " & Target.Address(0, 0) & " was changed from '" & OldVal & "' to '" & NewVal & "'"
OldVal = ""
NewVal = ""
End Sub
我遇到的问题是由于某种原因它永远不会显示以前的值。它只会在工作表 FA 单元格 B5 从 '' 更改为 '12' 时输出它,即使例如 10 之前在单元格中也是如此。
我也很想知道是否有一种方法可以让你拥有它,这样这段代码就不会一直运行。我更喜欢单击一个按钮,然后它将启动并开始记录更改。
谢谢