以下宏程序来自于百度知道网友的回答
实现目的:
在C4到Z100范围内,单元格内容发生变化时,将系统日期追加到该单元格的批注中
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("c4:z100")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target.Comment Is Nothing Then
Target.AddComment.Text Text:=CStr(Now())
Else
Target.Comment.Delete
Target.AddComment.Text Text:=CStr(Now())
End If
Target.Comment.Visible = False
End Sub
以下是我个人的修改
如果是判断某列内容修改,然后在该列后一列主键系统日期,则宏文件如下:
Private Sub Worksheet_Change(ByVal Target As Range)
'变更单元格的列号(1=A,2=B..)
Dim col As Integer
col = Target.Column
'变更单元格的行号
Dim row As Integer
row = Target.row
If col = 13 Or col = 16 Or col = 19 Or col = 22 Or col = 25 Or col = 28 Or col = 31 Then
'指定列之后列位置自动填写系统日期
Cells(row, col + 1) = CStr(Now())
End If
End Sub