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

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

实现目的:

在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


 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值