繁体   English   中英

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

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

因此,我有一个excel工作表,其中有一个范围A2:A3,我想知道是否可以将特定范围的最后一次更新时间存储到B1中的某个单元格中吗? 我在VBA世界中真的很了解。 会非常感谢您的帮助:)

  • 右键单击您的工作表标签
  • 查看代码
  • 复制并粘贴以下代码
  • 返回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

'已编写此宏,以更新每个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

点击查看输出

暂无
暂无

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

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