[英]Automatically adding the date/time to a cell when another cell is updated AND clearing it when this cell is empty
我正在為公司報告創建 excel 文件。 我從這個 MS 支持線程中借用了腳本 - LINK
它看起來像這樣:
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
它工作正常,但現在我希望在清除主單元格后清除目標單元格。
現在,例如,當我擦除 A1 時,A2 中的時間會停留在那里。
我是 Excel 的新手,希望能得到一些幫助:)
祝你有美好的一天!
...................................
您正在尋找代碼中的IsEmpty
檢查:
If IsEmpty(Target.Value) Then Target.Offset(1, 0).ClearContents Else Target.Offset(1, 0) = Now
整體而言:
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.