[英]Update date when related cell in same row is changed
Refering to this link : Automatic date update in a cell when another cell's value changes (as calculated by a formula)参考此链接: 当另一个单元格的值发生变化时,单元格中的自动日期更新(由公式计算)
Answer from Roman Is Helpful. Roman 的回答很有帮助。 but instead to store the oldvalue & oldDate to document properties, I'd prefer to store them in cell (table) within the same row.
但是为了将 oldvalue 和 oldDate 存储到文档属性中,我更愿意将它们存储在同一行的单元格(表)中。
here is what I try to change the function:这是我尝试更改功能的内容:
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
and in the formula cell let say "D1" I put:在公式单元格中让我说“D1”:
= UDF_EditDate(A1,B1,C1)
But, Unfortunately, this function doesn't work as expected.但是,不幸的是,此功能无法按预期工作。
any one could help me review and solve my problem?任何人都可以帮助我查看并解决我的问题?
The code below watches column A on a sheet, and when it is changed puts current date to the same row column B:下面的代码监视工作表上的 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
This will work correctly only if single cell is changed, try to modify it for multiple yourself这只有在更改单个单元格时才能正常工作,请尝试自己修改多个单元格
I did slight modification for extended number of column A to D and put the update on Column E for the corresponded row.我对 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.