Чтобы решить вашу проблему, просто измените ссылки с .Value = ""
на .clear
.
Также вам нужно добавить ссылку на лист, с которым вы работаете, иначе ваша ссылка на Range
может "запутать" макрос.
Пояснение
Dim wb As Workbook: Set wb = Workbooks(ThisWorkbook.Name) ' defines the workbook you are working in. You could change "ThisWorkbook" to the actual workbook name, but note that any changes to the workbook name (such as auto recover) will require you to modify this variable.
Dim ws As Worksheet: Set ws = wb.Worksheets("Sheet1") ' defines the worksheet within the workbook defined above.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim StaffRange As Range
Dim StaffTime As Range
Dim TrainerRange As Range
Dim TrainerTime As Range
Dim wb As Workbook: Set wb = Workbooks(ThisWorkbook.Name)
Dim ws As Worksheet: Set ws = wb.Worksheets("Sheet1")
Set StaffRange = ws.Range("B5:B40")
Set TrainerRange = ws.Range("D5:D40")
' If they put in initials in StaffRange then procede with entering the date stamp
If Not Intersect(Target, StaffRange) Is Nothing Then
Set StaffTime = ws.Range("C" & Target.Row)
If StaffTime.Value <> "" Then Exit Sub 'if there is already a date in field do not update and exit
StaffTime.Value = Now ' put in the date time
' now if they clear StaffRange then clear StaffTime
' cell cleared
ElseIf Intersect(Target, StaffRange) Is Nothing Then
Set StaffTime = ws.Range("C" & Target.Row)
' If StaffTime.Value = "" Then Exit Sub ' if it is already clear exit
StaffTime.clear ' make blank
' If they put in initials in TrainerRange then procede with entering the date stamp
ElseIf Not Intersect(Target, TrainerRange) Is Nothing Then
Set TrainerTime = ws.Range("E" & Target.Row)
If TrainerTime.Value <> "" Then Exit Sub
TrainerTime.Value = Now
' now if they clear TrainerRange then clear TrainerTime
' cell cleared
ElseIf Intersect(Target, TrainerRange) Is Nothing Then
clearing
Set StaffTime = ws.Range("E" & Target.Row)
' If StaffTime.Value = "" Then Exit Sub ' if it is already clear exit
StaffTime.clear ' make blank
End If
End Sub