简体   繁体   English

存储在单个单元格excel中的范围的最后更新日期

[英]last update date of a range stored in the single cell excel

So I have this excel worksheet, where I have a range A2:A3, I would like to know if I can store last time of update of that specific range to a cell lets say in B1? 因此,我有一个excel工作表,其中有一个范围A2:A3,我想知道是否可以将特定范围的最后一次更新时间存储到B1中的某个单元格中吗? I am really knew in VBA world. 我在VBA世界中真的很了解。 Will really appreciate any help :) 会非常感谢您的帮助:)

  • right click your sheet tab 右键单击您的工作表标签
  • View Code 查看代码
  • copy and paste in the code below 复制并粘贴以下代码
  • back to Excel 返回Excel

code

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng1 As Range
Set rng1 = Intersect([a2:a3], Target)
If rng1 Is Nothing Then Exit Sub
Application.EnableEvents = False
[b1] = Format(Now(), "dd-mm-yyyy hh:mm:ss")
Application.EnableEvents = True
End Sub

'This Macro has been written to update Last modified date/time on each A2:D43415 'Last Modified date applied to column F. '已编写此宏,以更新每个A2:D43415的上次修改日期/时间'上次修改日期应用于列F。

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rInt As Range
Dim rCell As Range
Dim tCell As Range
Dim tColInt As Integer

tColInt = 6 'Column Index, Example: A=1, B=2, ...... ,Z=26


Set rInt = Intersect(Target, Range("A2:D43415")) 'Change cell range
 If Not rInt Is Nothing Then
    For Each rCell In rInt
        Set tCell = Cells(rCell.Cells.Row, tColInt)
        If IsEmpty(tCell) Or Not IsEmpty(tCell) Then
            tCell = Now
            tCell.NumberFormat = "dd/mm/yyyy h:mm:ss AM/PM" 'Custom Format
        End If
    Next
 End If
End Sub

Click to See Output 点击查看输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM