SudLorSeeYeak
New Member
- Joined
- Jun 17, 2021
- Messages
- 2
- Office Version
- 2019
- Platform
- Windows
I am using this script below to record log to the sheet name "Log Record". The scrip will record 6 informations to six rows in the "Log Record" sheet when information in active sheet is changed (Cell changed, Sheet changed, Date/Time, User, Old value, New Value). It works fine when new value is put into single cell. However, when new values are pasted onto multiple ceIls, the 'Cell changed' will give range of cell changed in single line.
For example, if I made changes to cell A23, A24, A25 one cell at a time, 3 new lines appear in the "Log Record" sheet showing 3 old and new values input into the 3 cells. However, if I pasted 3 new values from another file to cell A23, A24, A25 in single paste, only one new line appear in the "Log Record" sheet showing I made changes to A23:A25 with only one single new value (but i changed 3 values in 3 cells).
I got this script from our IT and don't really know how I can modify it. Can anyone help modify the script so the it will log all changes made to multiple cells? The script are as below.
Dim PreviousValue As Variant
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PreviousValue = Target.Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NR As Long
If Intersect(Target, Range("A1:DW400")) Is Nothing Then Exit Sub
With Sheets("Log Record")
.Unprotect Password:="XXX"
NR = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & NR).Value = Target.Address(False, False)
.Range("B" & NR).Value = ActiveSheet.Name
.Range("C" & NR).Value = Now
.Range("D" & NR).Value = Environ("username")
.Range("E" & NR).Value = PreviousValue
.Range("F" & NR).Value = Target.Value
.Protect Password:="XXX"
End With
End Sub
For example, if I made changes to cell A23, A24, A25 one cell at a time, 3 new lines appear in the "Log Record" sheet showing 3 old and new values input into the 3 cells. However, if I pasted 3 new values from another file to cell A23, A24, A25 in single paste, only one new line appear in the "Log Record" sheet showing I made changes to A23:A25 with only one single new value (but i changed 3 values in 3 cells).
I got this script from our IT and don't really know how I can modify it. Can anyone help modify the script so the it will log all changes made to multiple cells? The script are as below.
Dim PreviousValue As Variant
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PreviousValue = Target.Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NR As Long
If Intersect(Target, Range("A1:DW400")) Is Nothing Then Exit Sub
With Sheets("Log Record")
.Unprotect Password:="XXX"
NR = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & NR).Value = Target.Address(False, False)
.Range("B" & NR).Value = ActiveSheet.Name
.Range("C" & NR).Value = Now
.Range("D" & NR).Value = Environ("username")
.Range("E" & NR).Value = PreviousValue
.Range("F" & NR).Value = Target.Value
.Protect Password:="XXX"
End With
End Sub