Entering current time in specific cells

Solved/Closed
friskymarsh
Posts
2
Registration date
Wednesday October 7, 2015
Status
Member
Last seen
October 20, 2015
- Oct 7, 2015 at 11:20 AM
rizvisa1
Posts
4479
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
- Oct 20, 2015 at 04:26 PM
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.
Related:

1 reply

rizvisa1
Posts
4479
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
769
Oct 7, 2015 at 12:19 PM
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
friskymarsh
Posts
2
Registration date
Wednesday October 7, 2015
Status
Member
Last seen
October 20, 2015

Oct 20, 2015 at 02:40 PM
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.
0
rizvisa1
Posts
4479
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
769
Oct 20, 2015 at 04:26 PM
if you want to have date entered next to the cell you touch, then you can use offset

target.offset(0,1) = now
0