Entering current time in specific cells

Solved/Closed
friskymarsh Posts 2 Registration date Wednesday 7 October 2015 Status Member Last seen 20 October 2015 - 7 Oct 2015 à 11:20
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 - 20 Oct 2015 à 16:26
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 response

rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
7 Oct 2015 à 12:19
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
friskymarsh Posts 2 Registration date Wednesday 7 October 2015 Status Member Last seen 20 October 2015
20 Oct 2015 à 14:40
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.
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
20 Oct 2015 à 16:26
if you want to have date entered next to the cell you touch, then you can use offset

target.offset(0,1) = now