2

所以我有这个excel工作表,我有一个范围A2:A3,我想知道我是否可以将该特定范围的最后一次更新存储到一个单元格中,比如说B1?我在 VBA 世界中非常了解。非常感谢任何帮助:)

4

2 回答 2

1
  • 右键单击您的工作表选项卡
  • 查看代码
  • 复制并粘贴下面的代码
  • 返回 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
于 2012-09-17T05:24:46.483 回答
0

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

点击查看输出

于 2018-08-17T04:08:35.817 回答