Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim isect As Range, cell As Range
Dim CellColour As Integer
Dim TimeStrText As String
Dim UserInput
Dim rValues As Range
If Not Application.Intersect(Target, Range("C4:AI43")) Is Nothing Then
Target(1).Value = UCase(Target(1).Value)
For Each cell In Range("C4:C43, H4:H43, M4:M43, R4:R43, W4:W43, AB4:AB43, AG4:AG43")
If cell.Value = Sheet2("ABSENCE CODES").Range("Tbl1") Then
cell.Offset(0, 0).Interior.ColorIndex = 4
cell.Offset(0, 0).Font.ColorIndex = 1
cell.Offset(0, 1).Interior.ColorIndex = 4
cell.Offset(0, 1).Font.ColorIndex = 4
cell.Offset(0, 2).Interior.ColorIndex = 0
cell.Offset(0, 2).Font.ColorIndex = 2
ElseIf cell.Value = Sheet2("ABSENCE CODES").Range("Tbl2") Then
cell.Offset(0, 0).Interior.ColorIndex = 3
cell.Offset(0, 0).Font.ColorIndex = 1
cell.Offset(0, 1).Interior.ColorIndex = 3
cell.Offset(0, 1).Font.ColorIndex = 3
cell.Offset(0, 2).Interior.ColorIndex = 0
cell.Offset(0, 2).Font.ColorIndex = 2
ElseIf cell.Value = Sheet2("ABSENCE CODES").Range("Tbl3") Then
cell.Offset(0, 0).Interior.ColorIndex = 6
cell.Offset(0, 0).Font.ColorIndex = 1
cell.Offset(0, 1).Interior.ColorIndex = 6
cell.Offset(0, 1).Font.ColorIndex = 6
cell.Offset(0, 2).Interior.ColorIndex = 0
cell.Offset(0, 2).Font.ColorIndex = 2
ElseIf cell.Value = Sheet2("ABSENCE CODES").Range("Tbl4") Then
cell.Offset(0, 0).Interior.ColorIndex = 8
cell.Offset(0, 0).Font.ColorIndex = 1
cell.Offset(0, 1).Interior.ColorIndex = 8
cell.Offset(0, 1).Font.ColorIndex = 8
cell.Offset(0, 2).Interior.ColorIndex = 0
cell.Offset(0, 2).Font.ColorIndex = 2
ElseIf cell.Value = Sheet2("ABSENCE CODES").Range("Tbl5") Then
cell.Offset(0, 0).Interior.ColorIndex = 45
cell.Offset(0, 0).Font.ColorIndex = 1
cell.Offset(0, 1).Interior.ColorIndex = 45
cell.Offset(0, 1).Font.ColorIndex = 45
cell.Offset(0, 2).Interior.ColorIndex = 0
cell.Offset(0, 2).Font.ColorIndex = 2
ElseIf cell.Value > 0 Then
cell.Offset(0, 0).Interior.ColorIndex = 0
cell.Offset(0, 1).Interior.ColorIndex = 0
cell.Offset(0, 2).Interior.ColorIndex = 0
cell.Offset(0, 0).Font.ColorIndex = 1
cell.Offset(0, 1).Font.ColorIndex = 1
cell.Offset(0, 2).Font.ColorIndex = 1
ElseIf cell.Value = "" Then
cell.Offset(0, 0).Interior.ColorIndex = 0
cell.Offset(0, 1).Interior.ColorIndex = 0
cell.Offset(0, 2).Interior.ColorIndex = 0
cell.Offset(0, 0).Font.ColorIndex = 1
cell.Offset(0, 1).Font.ColorIndex = 1
cell.Offset(0, 2).Font.ColorIndex = 1
End If
Next cell
End If
On Error GoTo EndMacro
If Not Application.Intersect(Target, Range("C4:D43, H4:I43, M4:N43, R4:S43, W4:X43, AB4:AC43, AG4:AH43")) Is Nothing Then
Target(1).Value = UCase(Target(1).Value)
If Application.Intersect(Target, Range("C4:E43, H4:J43, M4:O43, R4:T43, W4:Y43, AB4:AD43, AG4:AI43")) Is Nothing Then
If Not Intersect(Target, [E44, J44, O44, T44, Y44, AD44, AI44]) Is Nothing Then
If Not Selection.Cells.Count = 1 Then
' Application.Undo
Application.EnableEvents = False
If Target.Value < 1 Then
UserInput = Format(Int(Target.Value * 24) * 100 + ((Target.Value * 24) - Int(Target.Value * 24)) * 60, "000")
Else
UserInput = Format(Target.Value, "000")
End If
If Len(UserInput) > 1 Then
Target = Left(UserInput, Len(UserInput) - 2) & ":" & Right(UserInput, 2)
End If
Application.EnableEvents = True
End If
End If
End If
End If
If Target.Cells.Count > 1 Then
End If
If Target.Value = "" Then
End If
If Target.Column = "1" Then
End If
Application.EnableEvents = False
With Target
If .HasFormula = False Then
Select Case Len(.Value)
Case 1 ' e.g., 1 = 00:01
TimeStrText = "00:0" & .Value
Case 2 ' e.g., 12 = 00:12 AM
TimeStrText = "00:" & .Value
Case 3 ' e.g., 735 = 7:35 AM
TimeStrText = Left(.Value, 1) & ":" & _
Right(.Value, 2)
Case 4 ' e.g., 1234 = 12:34
TimeStrText = Left(.Value, 2) & ":" & _
Right(.Value, 2)
Case 5 ' e.g., 1 = 00:00
TimeStrText = "24:00" & .Value
Case Else
Err.Raise 0
End Select
.Value = TimeValue(TimeStrText)
End If
End With
Application.EnableEvents = True
EndMacro:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Any pointers or suggestions would be helpful
Bookmarks