Entering current time in specific cells [Solved/Closed]

Report
Posts
2
Registration date
Wednesday October 7, 2015
Status
Member
Last seen
October 20, 2015
-
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
-
Hi, I am using a workbook where I record the time that I give each of my students an exam. I am using a tablet and I would like to be able to touch (or click) a specific cell to enter the current time. I found some code on this site that allows me to enter the time by clicking, but I don't know how to write it so that it will only apply to specific cells. Here is the code:

If Target.Address = ActiveCell.Address Then

Target = Format(Now, "ttttt")

End If

I would appreciate any help.

1 reply

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
764
you can try to use the event
if you go to VBE
and click on your sheet
there you can try code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'prevent Select event triggering again
Application.EnableEvents = False

'ensure that only one cell is selected
If (Target.Count = 1) Then
'ensure that cell selected is from range A1:A10
If (Not Intersect(Target, Range(Cells(1, "a"), Cells(10, "A"))) Is Nothing) Then
'put current date and time
Target = Now
End If
End If
'enable the event again
Application.EnableEvents = True
End Sub
7
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2942 users have said thank you to us this month

Posts
2
Registration date
Wednesday October 7, 2015
Status
Member
Last seen
October 20, 2015

Thanks for the help. Sorry for the delay in responding. Your solution works well, but because of my lack of knowledge, I am having troubling specifying the specific cells I want to use this event in. ie, I want to touch a cell on my tablet to enter the time, but I need to be able to enter data into the adjacent cell.
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
764
if you want to have date entered next to the cell you touch, then you can use offset

target.offset(0,1) = now

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!