Hello everyone
I am working on a code whereby I click on my "enter time" command button and then it displays current time in the first column then I hit enter time in the second column again and it stops the clock and shows me the time as well and then shows elapsed time in the third column . However, I want to lock the cells in the first two columns and password protect them.Additionally, I want to clear the first two columns when the clear button is clicked. Could I get some help please since I am totally new to VBA? Thanks
My code is as following
Private Sub CommandButton1_Click()
Worksheets("Sheet1").Activate
ActiveCell.Value = Format(Now, "mm/dd/yy hh-mm")
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
Set MyRange = Intersect(Range("A2:A5,B2:B5"), Target)
If Not MyRange Is Nothing Then
Sheets("Sheet1").Unprotect Password:="admin"
MyRange.Locked = True
Sheets("Sheet1").Protect Password:="admin"
End If
End Sub
Sub Clear_Command()
Worksheets("Sheet1").Activate
Sheets("Sheet1").Unprotect Password:="admin"
Range("A2:A5,B2:B5").ClearContents
End Sub
Sub EnterCurrentTime()
'
' EnterCurrentTime Macro
' This macro enters the current time into the active cell
'
'
Worksheets("Sheet1").Activate
Sheets("Sheet1").Unprotect Password:="admin"
ActiveCell.Value = Now()
Sheets("Sheet1").Protect Password:="admin"
End Sub
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
Untitled.png
Bookmarks