所以我有这个excel工作表,我有一个范围A2:A3,我想知道我是否可以将上一次特定范围的更新存储到一个单元格让我们说在B1? 我真的很了解VBA世界。 非常感谢任何帮助:)
答案 0 :(得分:1)
<强> 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
答案 1 :(得分: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