So I'm using this code to put a username and time stamp when a user starts an entry in Column B. The code works perfectly, until the user decides that they don't really want to make an entry and they backspace it out. The username and timestamp remain. The other problem is that if a user deletes the row the code breaks. What I need to be able to do is if the user decides that they made a mistake on that line and either delete it or back space it out the username and time stamp go away as well. The shaded area will be locked so the user can't backspace that out.
Any help would be most appreciated.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B4:B2000")) Is Nothing Then Exit Sub
Application.EnableEvents = False
With Target
.Offset(, 6).Value = Environ("username")
.Offset(, 7).Value = Date
End With
Application.EnableEvents = True
End Sub
Any help would be most appreciated.
Book1 - Copy.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
B | C | D | E | F | G | H | I | |||
1 | ||||||||||
2 | ||||||||||
3 | STW (Person Working) | STO (Person Not Working) | Date Shift Trade Will Occur | Time Start | Time End | Total Hours Traded Off | Person Who Made This Entry | Date Person Made This Entry | ||
4 | Name #08 | Name #03 | 01/17/23 | 0400 | 0800 | 4.0 | ||||
5 | Name #03 | Name #01 | 02/27/23 | 1200 | 1630 | 4.5 | ||||
6 | Name #04 | Name #03 | 03/15/23 | 1300 | 1830 | 5.5 | ||||
7 | Name #06 | Name #01 | 04/22/23 | 0430 | 0730 | 3.0 | ||||
8 | Name #02 | Name #04 | 04/28/23 | 0730 | 2000 | 12.5 | ||||
9 | Name #08 | Name #04 | 05/02/23 | 1130 | 1730 | 6.0 | ||||
10 | Name #05 | Name #02 | 05/14/23 | 0330 | 1200 | 8.5 | ||||
11 | Name #01 | Name #03 | 06/12/23 | 1800 | 2000 | 2.0 | ||||
12 | Name #07 | Name #01 | 07/04/23 | 1700 | 2400 | 7.0 | ||||
13 | Name #71 | Name #02 | 07/30/23 | 0330 | 0730 | 4.0 | ||||
14 | Name #08 | Name #02 | 08/02/23 | 0330 | 1200 | 8.5 | ||||
15 | Name #110 | Name #72 | 08/17/23 | 1300 | 1800 | 5.0 | ||||
16 | Name #119 | Name #118 | 08/18/23 | 1300 | 1800 | 5.0 | ||||
17 | Name #06 | Name #04 | 08/19/23 | 0330 | 1200 | 8.5 | ||||
18 | Name #22 | Name #01 | 09/22/23 | 0800 | 1200 | 4.0 | ||||
19 | Name #114 | Name #105 | 09/27/23 | 1200 | 1800 | 6.0 | ||||
20 | Name #117 | 0.0 | Randy | 5/8/2023 | ||||||
21 | 0.0 | |||||||||
22 | 0.0 | |||||||||
23 | 0.0 | |||||||||
Shift Trades |
Cell Formulas | ||
---|---|---|
Range | Formula | |
G4:G23 | G4 | =(TEXT(F4,"00\:00")-TEXT(E4,"00\:00"))*24 |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
B4:C23 | List | =Data!$B$4:$B$149 |