在任何一个表的名称点击右键选“查看代码”,在空白框中输入以下代码:
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Column <> 1 Then Exit Sub
For 行 = .Row To .Row + .Rows.Count - 1
If Cells(行, 1) <> "" Then
Cells(行, 2) = Format(Now, "yyyy/mm/dd hh:mm:ss修改")
Else
Cells(行, 2) = ""
End If
Next
End With
End Sub
关闭代码框后,只要在A列输入或修改内容,B列就可以显示修改的时间了。这是参考网上的方法作了点修改,希望对你有用。
将宏放到工作表事件中,所有修改的时间就会记录下来,点击单元格可以看到时间:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
For Each c In Target.Cells
With c.Validation
.Delete: .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator:=xlBetween
.IgnoreBlank = True: .ShowInput = True
.InputMessage = "最后修改时间" & Format(Now(), "yyyy-m-d hh:mm:ss")
End With
Next c
End Sub