Entering current time in specific cells [Solved/Closed]

Posts
2
Registration date
Wednesday October 7, 2015
Status
Member
Last seen
October 20, 2015
- - Latest reply: rizvisa1
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
- 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.
See more 

1 reply

Best answer
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
754
7
Thank you
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

Say "Thank you" 7

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

CCM 5920 users have said thank you to us this month

friskymarsh
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.
rizvisa1
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
754 -
if you want to have date entered next to the cell you touch, then you can use offset

target.offset(0,1) = now