I have written the following code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("C7:F20"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 0).ClearContents
Else
With .Offset(0, 0)
.NumberFormat = "mmm dd yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub
I am using this code to create time sheets in excel. I have created the sheet with Four columns.
Column "C" is used to "log in"". All the user has to do is place an "X" in the cell, and I have it autopopulating with the date and time.
Column "D" is used to "log out for lunch". Again, all the user has to do is place an "X" in the cell, and it will autopopulate with the current date and time.
Column "E" is used to "log in after lunch". Again, all the user has to do is place an "X" in the cell, and it will autopopulate with the current date and time.
Column "F" is used to "log out". Again, all the user has to do is place an "X" in the cell, and it will autopopulate with the current date and time.
I would actually like to add a column between "C" and "D" which will show the user name of the person that "logged in". This will ultimately make column "D" which is used to "log out for lunch" change and become column "E". I would then like to add column "F" to show the user name of the person that "logged out for lunch" and so on for the other two columns.
I can't figure out how to change my code to accomodate this. I'm completely new to this, and am impressed that I have gotten this far as I am completely "self taught" when it comes to Excel, but any help that I could get would be most appreciated. I'm hoping this all makes sense.
Thanks, LS
Bookmarks