我想在单击单元格时在excel文档中添加当前系统时间。
码
If Target.Address = ActiveCell.Address Then
Target = Format(Now, "ttttt")
End If
答案 0 :(得分:1)
您可以将其限制在Intersect
范围内,如下所示。在处理活动时,您应该:
Change
事件的特定问题)Target
是否适用于多个单元格或仅适用于单个单元格。代码使用DoubleClick
事件
工作表模块代码
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim rng1 As Range
Set rng1 = Intersect(Target, Range("A1:a10"))
If rng1 Is Nothing Then Exit Sub
Application.EnableEvents = False
rng1 = Format(Now, "ttttt")
Application.EnableEvents = True
End Sub
答案 1 :(得分:0)
假设您的代码位于SelectionChange
事件中:
If Target.Cells.Count = 1 Then
If Not Application.Intersect(Target, Me.Range("RangeYouWantItToWorkFor") Is Nothing Then
'...