Reputation: 25
I would like to add current system time in an excel document when i should click on the cell.
code
If Target.Address = ActiveCell.Address Then
Target = Format(Now, "ttttt")
End If
Upvotes: 0
Views: 42
Reputation: 55672
You can restrict it to a range Intersect
as below. When working with events you should:
Change
event)Target
applies to multiple cells or just a single cell.code below uses DoubleClick
event
sheet module code
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
Upvotes: 1
Reputation: 53137
Assuming your code is in the SelectionChange
event:
If Target.Cells.Count = 1 Then
If Not Application.Intersect(Target, Me.Range("RangeYouWantItToWorkFor") Is Nothing Then
'...
Upvotes: 0