Maybe indenting your code differently would make the solution more evident:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo errHandler
If Target.Count = 1 Then
If Target.Column = 1 Then
Application.EnableEvents = False
If Target.Value <> "" Then
Target.Offset(0, 6).Value = Format(Date)
Target.Offset(0, 5).Value = Format(Time(), "hh:mm")
If Target.Offset(0, 5).Value >= TimeValue("07:00:00") _
And Target.Offset(0, 5).Value < TimeValue("15:00:00") _
Then Target.Offset(0, 7) = "1st Shift"
If Target.Offset(0, 5).Value >= TimeValue("15:00:00") _
And Target.Offset(0, 5).Value < TimeValue("23:00:00") _
Then Target.Offset(0, 7) = "2nd Shift"
If Target.Offset(0, 5).Value >= TimeValue("23:00:00") _
Or Target.Offset(0, 5).Value < TimeValue("07:00:00") _
Then Target.Offset(0, 7) = "3rd Shift"
End If
End If
End If
If Target.Value = "" Then
Target.Offset(0, 5).ClearContents
Target.Offset(0, 6).ClearContents
Target.Offset(0, 7).ClearContents
End If
errHandler:
Application.EnableEvents = True
End Sub
You're only disabling events when you change a single cell in column A.
I'm guessing that you want something like:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo errHandler
If Target.Count = 1 Then
If Target.Column = 1 Then
Application.EnableEvents = False
If Target.Value <> "" Then
Target.Offset(0, 6).Value = Format(Date)
Target.Offset(0, 5).Value = Format(Time(), "hh:mm")
If Target.Offset(0, 5).Value >= TimeValue("07:00:00") _
And Target.Offset(0, 5).Value < TimeValue("15:00:00") _
Then Target.Offset(0, 7) = "1st Shift"
If Target.Offset(0, 5).Value >= TimeValue("15:00:00") _
And Target.Offset(0, 5).Value < TimeValue("23:00:00") _
Then Target.Offset(0, 7) = "2nd Shift"
If Target.Offset(0, 5).Value >= TimeValue("23:00:00") _
Or Target.Offset(0, 5).Value < TimeValue("07:00:00") _
Then Target.Offset(0, 7) = "3rd Shift"
Else
Target.Offset(0, 5).ClearContents
Target.Offset(0, 6).ClearContents
Target.Offset(0, 7).ClearContents
End If
End If
End If
errHandler:
Application.EnableEvents = True
End Sub
Chip,
That is correct, I was referring to the calculation tab settings. How ever I
thought that this would fix my problem but it doesn't. The problem is when
clearing any cell value other than the A column with a back space or delete
key I get the "hour glass" showing until I hit the esc key.
Then I get the option to debug, end, continue or help. When I go to the
debug mode my code is cycling over and over. If I use the "clear contents"
selection when right clicking with the mouse it never happens.
Below is the code that I'm using.
-----------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo errHandler
If Target.Count = 1 Then
If Target.Column = 1 Then
Application.EnableEvents = False
If Target.Value <> "" Then
Target.Offset(0, 6).Value = Format(Date)
Target.Offset(0, 5).Value = Format(Time(), "hh:mm")
If Target.Offset(0, 5).Value >= TimeValue("07:00:00") _
And Target.Offset(0, 5).Value < TimeValue("15:00:00") _
Then Target.Offset(0, 7) = "1st Shift"
If Target.Offset(0, 5).Value >= TimeValue("15:00:00") _
And Target.Offset(0, 5).Value < TimeValue("23:00:00") _
Then Target.Offset(0, 7) = "2nd Shift"
If Target.Offset(0, 5).Value >= TimeValue("23:00:00") _
Or Target.Offset(0, 5).Value < TimeValue("07:00:00") _
Then Target.Offset(0, 7) = "3rd Shift"
End If
End If
End If
If Target.Value = "" Then
Target.Offset(0, 5).ClearContents
Target.Offset(0, 6).ClearContents
Target.Offset(0, 7).ClearContents
End If
errHandler:
Application.EnableEvents = True
End Sub
-----------------------------------------------------
Any help is greatly appreciated.
Regards,
Brian
--