VBA Code To Lock An Active Cell

Flani

New Member
Joined
Jul 11, 2012
Messages
17
So I have a code below that when you double click a cell in Column C, it will perform a stopwatch in Column D and E and what you double click on any other cell besides column c, the time expires. I need to lock that from there protecting it with a password so nobody can change the log time as people might change it. It should get precisely the amount of time spent for a particular process. so when i double click on a different cell to stop the time, can the cells in column d and f be locked?

And how can I lock the module for this too so that nobody can mess up with the code?

Rich (BB code):
Rich (BB code):
Public stopMe As Boolean
Public resetMe As Boolean
Public myVal As Variant


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column = 3 Then
        If Target.Value = myVal And Target.Value <> "" Then
            'Changed
            Dim startTime, finishTime, totalTime, timeRow
            startTime = Timer
            stopMe = False
            resetMe = False
            myTime = Target.Offset(, 4).Value
            Target.Offset(, 3).Select
startMe:
            DoEvents
            timeRow = Target.Row
            finishTime = Timer
            totalTime = finishTime - startTime
            Target.Offset(, 1).Value = Format(myTime + totalTime, "00.00")
            If resetMe = True Then
                Target.Offset(, 3).Value = 0
                Target.Offset(, 4).Value = 0
                stopMe = True
            End If
            If Not stopMe = True Then
                Target.Offset(, 2).Value = totalTime
                GoTo startMe
            End If
            Cancel = True
            End
        Else
            'Not Changed
            stopMe = True
            Cancel = True
        End If
    End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    myVal = Target.Value
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
To lock the module, you need to go to it in VBA right click on the module and go to VBAProject properties, there will be two tabs a general and a protection select protection then add your password save and close the file. you will have to reopen it to see that the protection is in place. as for locking the cells in VBA for your above code I cut and pasted it into VBA and I cant get it to work. is there more to your program than posted.
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,142
Members
448,551
Latest member
Sienna de Souza

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