• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Break tracker insert current time after double click on cell

Abhijeet

Active Member
Hi

I want to create Break tracker after double click on particular range double click then insert current time & lock that cells no need to input apart from double click insert any value

Not able to edit that cell after insert time please tell me how to do this
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
On Error Resume Next
Dim rng As Range
Set rng = Range("TimeEntry")

If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, rng) Is Nothing Then
    Application.EnableEvents = False
    Cancel = True 'stop the edit mode
  With Target
        If .Value = "" Then
            .Value = Time
            .Offset(0, 1).Activate
        End If
    End With
End If
Application.EnableEvents = True

End Sub
 

Attachments

  • Break.xls
    72.5 KB · Views: 3
Code looks fine. But you don't have "TimeEntry" defined as Named Range in your Workbook.

Either define it or change below line...
Code:
Set rng = Range("TimeEntry")

To...
Code:
Set rng = UNION(Range("F4:G65"),Range("J4:K65"),Range("N4:O65"))

Edit: To lock the cell, just use sheet protection with cell originally set to Unlocked and then lock it after value changes from blank.
 
Last edited:
Edit: To lock the cell, just use sheet protection with cell originally set to Unlocked and then lock it after value changes from blank.

In this case before enter anything user can insert manually time i want to restrict that as well only double click will work in those cells
 
First protect your sheet.

Use code below and change password as needed.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
On Error Resume Next
Dim rng As Range
Set rng = Union(Range("F4:G65"), Range("J4:K65"), Range("N4:O65"))

If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, rng) Is Nothing Then
    Application.EnableEvents = False
    Cancel = True 'stop the edit mode
With Target
        If .Value = "" Then
            ActiveSheet.Unprotect "Your Password"
            .Value = Time
            .Offset(0, 1).Activate
            ActiveSheet.Protect "Your Password"
        End If
    End With
End If
Application.EnableEvents = True

End Sub
 
Back
Top