【问题标题】:Add timestamp and name to modified row将时间戳和名称添加到修改的行
【发布时间】:2019-11-22 09:06:25
【问题描述】:

我想创建一个新的 Excel 工作表,在每个修改的行中包含时间和名称戳。

我正在使用此代码:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A3:P9999")) Is Nothing Then Exit Sub
Application.EnableEvents = False
With Target
    Cells(ActiveCell.Row() - 1, 18) = Date
    Cells(ActiveCell.Row() - 1, 17) = Environ("username")
End With
Application.EnableEvents = True
End Sub

在没有将-1 添加到Cells 行的情况下,我在活动(已修改)单元格下方获得了邮票。

我添加了-1,但现在当我点击delete 按钮清除该单元格时,我在活动单元格上方标记了一行。

【问题讨论】:

    标签: excel vba timestamp


    【解决方案1】:

    使用Target(更改后的单元格),而不是ActiveCell。完成单元格编辑后,默认情况下,您将在下面的单元格中结束,因此该单元格将处于活动状态。

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Intersect(Target, Range("A3:P9999")) Is Nothing Then Exit Sub
    
    Application.EnableEvents = False
    
    With Target
        Cells(.Row, 18) = Date
        Cells(.Row, 17) = Environ("username")
    End With
    
    Application.EnableEvents = True
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-21
      • 2017-12-01
      • 1970-01-01
      • 2010-10-26
      • 2014-03-18
      • 2019-01-28
      • 2019-10-02
      相关资源
      最近更新 更多