我在VBA中有这个代码,按双击实际日期和时间填充单元格,但如果不重写带有日期的现有单元格,我不能做第二个。 这是代码
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A1:A5000")) Is Nothing Then
Cancel = True
Target.Formula = Date + Time
Else
If Not IsEmpty(ActiveCell.Value) Then
MsgBox "You can not overwrite date!"
End If
End If
End Sub
我如何重新使用此代码,不要覆盖带日期的现有单元格? Sry for my english :) 问候。
答案 0 :(得分:1)
也许你需要这个......
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A1:A5000")) Is Nothing Then
Cancel = True
If Not IsDate(Target) Then
Target.Formula = Now
Else
MsgBox "You can not overwrite date!"
End If
End If
End Sub