该代码在F列中自动插入日期有两个小问题。
1)现在,如果我单击E单元格,则日期会更改,即使在此之前我没有在其中键入任何内容...,也可以更改它,它应该在我在其中插入任何值后才起作用,而不仅仅是单击?
2)我试图格式化添加此行的日期:
r.Offset(0, 1).Value = Date & " " & Time
r.Offset(0, 1).Value.NumberFormat = "mm/dd/yyyy hh:mm"
但是我遇到错误,我在做什么错了?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim E As Range, F As Range, Inte As Range, r As Range
Set E = Range("E:E")
Set Inte = Intersect(E, Target)
If Inte Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each r In Inte
If r.Offset(0, 1).Value = "" Then
r.Offset(0, 1).Value = Date
End If
Next r
Application.EnableEvents = True
End Sub
答案 0 :(得分:1)
尝试一下:
r.Offset(0, 1) = Now
r.Offset(0, 1).NumberFormat = "mm/dd/yyyy hh:mm"
答案 1 :(得分:0)
r.Offset(0, 1).Value = FORMAT(NOW(), "mm/dd/yyyy hh:mm")