简体   繁体   English

更改同一行中的相关单元格时更新日期

[英]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这只有在更改单个单元格时才能正常工作,请尝试自己修改多​​个单元格

Thanks to avb感谢av

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.

相关问题 当单元格在该列的同一行中更改时,如何在特定列中输入日期/时间戳? - How do I enter the date/time stamp in specific column when a cell is changed in the same row of that column? Excel-第一次更改另一个单元格时用日期时间更新列 - Excel - Update Column with Date Time when Another Cell is First Changed 单元格中的值更改时,将数据插入同一行 - Insert data in same row when a value in a cell is changed 当数据输入到同一行的另一个单元格时,Excel 公式将日期/时间放在单元格中 - Excel Formula which places date/time in cell when data is entered in another cell in the same row 如果同一行中的一系列单元格发生任何更改,Excel VBA将更新单元格中的日期 - Excel VBA update the date in a cell if anything changes in a range of cells in the same row 其他单元格值更改时如何将单元格值更新为“”? - How to update cell value to "" when other cell value changed? 当另一列的同一行单元格具有今天的日期时,创建列的索引 - create index of column when same row cell of another column has today's date 在单元格中更改新数据时,将一行数据移到顶部 - Move a row of data on top when new data changed in a cell 更改单元格时自动更新(计算)Excel工作表 - Auto-update (calculate) the Excel sheet when a cell is changed Excel,当其他单元格更改值或字符串时,停止立即更新NOW() - Excel, Stop update NOW(), when other cell changed value or string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM