我正在编写一个代码,当C列到R列中的任何单元格发生更改时,更改T列中的日期。
代码工作,但它使工作簿超级滞后和缓慢。有没有办法让这段代码更有效率?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WorkRng As Range, rrow As Long
Dim Rng As Range
Set WorkRng = Intersect(Range("B1:R300"), Target)
If Not WorkRng Is Nothing Then
For Each Rng In WorkRng
rrow = Rng.Row
If Not Rng.Value = "" Then
Cells(rrow, "T").Value = Now
Cells(rrow, "T").NumberFormat = "dd/mm/yyyy h:mm"
Else
Cells(rrow, "T").ClearContents
End If
Next
End If
End Sub
2条答案
按热度按时间bxjv4tth1#
如果您想在B:R列中没有数据时清除时间戳,请尝试以下操作
p1tboqfb2#
时间戳在选定范围中的每一行更改时更新,如果行中的所有单元格都没有值,则删除时间戳。