Excel单元格内容变化时,自动添加系统时间批注(亲自实践)

来源:互联网 发布:apache视频教程 编辑:程序博客网 时间:2024/05/16 10:58

以下宏程序来自于百度知道网友的回答

实现目的:

在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 = FalseEnd 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 IfEnd Sub


 

 

原创粉丝点击