Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lr&, oldV As String, newV As String
lr = Range("A5").End(xlDown).Row ' dong cuoi cung trong cot A
If Target.Count > 1 Then Exit Sub
'If Target.Column = 1 Or Target.Column = 3 Or Target.Column = 3 Then ' Xet thay doi trong cot A,C,E
If Target.Column <= 20 Then ' Xet thay doi trong cot A den T (cot thu 20)
If Target.Row > 4 And Target.Row <= lr Then ' neu dong lon hon 5 va nho hon dong cuoi cung
With Application
.ScreenUpdating = False
.EnableEvents = False
newV = Target.Value ' luu gia tri moi
.Undo
oldV = Target.Value ' luu gia tri cu
Target.Value = newV ' phuc hoi gia tri moi
.EnableEvents = True
If oldV = newV Then Exit Sub ' neu khong co su thay doi thi thoat
'Cells(Target.Row, "Z").Value = Now ' luu thoi gian vao cot Z
If Not Target.Comment Is Nothing Then _
'Target.Comment.Delete ' Xoa comment cu
Target.Comment.Text Target.Comment.Text & vbCrLf & oldV & " - " & Format(Now, "dd/mm/yyyy hh:mm:ss") 'add them giu lai comment cu'
Else
Target.AddComment oldV & " - " & Format(Now, "dd/mm/yyyy hh:mm:ss") ' add comment moi
End If
.ScreenUpdating = True
End With
End If
End If
End Sub