![](/img/trans.png)
[英]How do I enter the date/time stamp in specific column when a cell is changed in the same row of that column?
[英]Update date when related cell in same row is changed
參考此鏈接: 當另一個單元格的值發生變化時,單元格中的自動日期更新(由公式計算)
Roman 的回答很有幫助。 但是為了將 oldvalue 和 oldDate 存儲到文檔屬性中,我更願意將它們存儲在同一行的單元格(表)中。
這是我嘗試更改功能的內容:
Public Function UDF_EditDate(ByVal newData As Range, ByRef oldData As Range, ByRef oldDate As Range) As Date
If newData.Count = 1 And oldData.Count = 1 And oldDate.Count = 1 Then
If (oldDate.Value = "") Or (newData.Value <> oldData.Value) Then
oldData.Value = newData.Value
Range(oldDate).Value = Now()
End If
UDF_EditDate = Now()
End If
End Function
在公式單元格中讓我說“D1”:
= UDF_EditDate(A1,B1,C1)
但是,不幸的是,此功能無法按預期工作。
任何人都可以幫助我查看並解決我的問題?
下面的代碼監視工作表上的 A 列,並在更改時將當前日期放在同一行 B 列中:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Target.Parent.Range("A:A")) Is Nothing Then Exit Sub
Target.Next.Value = Date
End Sub
這只有在更改單個單元格時才能正常工作,請嘗試自己修改多個單元格
感謝av
我對 A 列到 D 列的擴展數量進行了輕微修改,並將相應行的 E 列更新。
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Target.Parent.Range("A:D")) Is Nothing Then Exit Sub
For Each x In Target
Cells(x.Row, 5).Value = Now
Next
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.