Double click only Time

DBarley17022

New Member
Joined
Feb 26, 2019
Messages
4
I have a sign in/out sheet That Columns D2:2000, E2:2000 once double clicked enter current time. what I need is that It can be only double click. and not manually entered. I already have the VBA code that enters current time on double click.
Current codes are;
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Not Intersect(Target, Range("A2:A2000")) Is Nothing Then
Target.Value = Date
Cancel = True
ElseIf Not Intersect(Target, Range("D2:D2000,E2:E2000")) Is Nothing Then
Target.Value = Time
Cancel = True
End If
End Sub

any suggestion would be helpful.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
The date could be auto-entered when cell is clicked using Worksheet_SelectionChange with a line to auto-activate a different cell (this preventing user from entering anything manually in the cell)
Double-click
event on same cells could be password protected to allow cell edit where required
 
Upvote 0
The date could be auto-entered when cell is clicked using Worksheet_SelectionChange with a line to auto-activate a different cell (this preventing user from entering anything manually in the cell)
Double-click
event on same cells could be password protected to allow cell edit where required


I'm not worried about the date. I have a select few kids that thinks it funny to put in what ever time they wish. The time being accurate is the most important part, It's for their own protection.
 
Upvote 0
Hi and welcome to the MrExcel board!
Try this:
Rich (BB code):
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Application.EnableEvents = False
  If Not Intersect(Target, Range("A2:A2000")) Is Nothing Then
    Target.Value = Date
    Cancel = True
  ElseIf Not Intersect(Target, Range("D2:E2000")) Is Nothing Then
    Target.Value = Time
    Cancel = True
  End If
  Application.EnableEvents = True
End Sub
 
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Rng As Range, v
  Set Rng = Intersect(Target, Range("A2:A2000,D2:E2000"))
  If Rng Is Nothing Then Exit Sub
  For Each v In Rng
    If v <> Empty Then  ' <-- Allow cell cleaning
      Application.EnableEvents = False
      Target.Select
      MsgBox "Use double click to enter date-time into columns A,D,E", vbExclamation, "Not allowed"
      Application.Undo
      Application.EnableEvents = True
      Exit For
    End If
  Next
End Sub
Regards
 
Last edited:
Upvote 0
I currently don't know how to write VBA, which is why I joined here! But seriously I should take some classes on this!
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top