古い値と新しい値を呼び出すために使用しているこのコードがあります。ただし、ユーザーが単純に a を強調表示して削除を押すと実行され、その変更が記録されるという問題が発生していますが、何らかの理由で同じ要求のインスタンスがさらに多く実行されます。一度だけ実行する方法はありますか?ありがとう
Public OldValues As New Collection
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Sheets("Pagination").Range("J11") <> "Yes" Then Exit Sub
'Copy old values
Set OldValues = Nothing
Dim c As Range
For Each c In Target
OldValues.Add c.Value, c.Address
Next c
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Sheets("Pagination").Range("J11") <> "Yes" Then Exit Sub
On Local Error Resume Next ' To avoid error if the old value of the cell address you're looking for has not been copied
Dim c As Range
For Each c In Target
Sheets("corrections").Cells(Rows.Count, "A").End(xlUp)(2).Value = Now & " Sheet " & ActiveSheet.Name & " Cell " & Target.Address(0, 0) & " has a new value of " & c.Value & "; old value was " & OldValues(c.Address)
Next c
'Copy old values (in case you made any changes in previous lines of code)
Set OldValues = Nothing
For Each c In Target
OldValues.Add c.Value, c.Address
Next c
End Sub