[英]Automatically adding the date/time to a cell when another cell is updated AND clearing it when this cell is empty
I'm creating excel file for company reports.我正在为公司报告创建 excel 文件。 I've borrowed script from this MS Support thread - LINK
我从这个 MS 支持线程中借用了脚本 - LINK
It looks like that:它看起来像这样:
Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Or _
Not Intersect(Target, Range("B1")) Is Nothing Or _
Not Intersect(Target, Range("C1")) Is Nothing Or _
Not Intersect(Target, Range("D1")) Is Nothing Or _
Not Intersect(Target, Range("E1")) Is Nothing Then
Target.Offset(1, 0) = Now
End If
End Sub
It works fine but now i want target cells to be cleared after cleaing main cells.它工作正常,但现在我希望在清除主单元格后清除目标单元格。
Now when for example i erase A1, the time in A2 stays there.现在,例如,当我擦除 A1 时,A2 中的时间会停留在那里。
I'm quite new in Excel and hope for some help:)我是 Excel 的新手,希望能得到一些帮助:)
Have a good day!祝你有美好的一天!
............................... ...................................
You are looking for an IsEmpty
check in your code:您正在寻找代码中的
IsEmpty
检查:
If IsEmpty(Target.Value) Then Target.Offset(1, 0).ClearContents Else Target.Offset(1, 0) = Now
As a whole:整体而言:
Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:E1")) Is Nothing Then
If IsEmpty(Target.Value) Then Target.Offset(1, 0).ClearContents Else Target.Offset(1, 0) = Now
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.