Private Sub Worksheet_Change(ByVal Target As Range)
'Highlight cells according to date
If Not Intersect(Target, Range("H5:AA16")) Is Nothing Then
If IsEmpty(Target) = True Then
With Target
.Style = "Normal"
.HorizontalAlignment = xlCenter 'keep cell format
.VerticalAlignment = xlCenter
.BorderAround xlContinuous, xlThin
With .Font
.Name = "Calibri"
.Size = 11
End With
End With
ElseIf Target.Value < Date Then
Target.Style = "Bad"
ElseIf Target.Value = "-" Then
'do nothing
ElseIf Target.Value > Date Then
Target.Style = "Good"
ElseIf Target.Value = Date Then
Target.Interior.ColorIndex = 0
Target.Font.ColorIndex = 1
End If
End If
'Auto populate
If Not Intersect(Target, Range("Q5:Q16")) Is Nothing Then
If IsEmpty(Target) = True Then
'do nothing
ElseIf IsEmpty(Target) = False Then
Application.EnableEvents = False 'Prevent looping based on change caused by auto pop
Target.Cells(1, 2).Value = DateAdd("d", 60, Target.Value)
If Target.Cells(1, 2).Value < Date Then
Target.Cells(1, 2).Style = "Bad"
ElseIf Target.Cells(1, 2).Value > Date Then
Target.Cells(1, 2).Style = "Good"
ElseIf Target.Cells(1, 2).Value = Date Then
Target.Cells(1, 2).Interior.ColorIndex = 0
Target.Cells(1, 2).Font.ColorIndex = 1
End If
Application.EnableEvents = True 'Allow events again
End If
End If
'Auto populate
If Not Intersect(Target, Range("M5:M16")) Is Nothing Then
If IsEmpty(Target) = True Then
'do nothing
ElseIf IsEmpty(Target) = False Then
Application.EnableEvents = False
Target.Cells(1, 2).Value = DateAdd("d", 7, Target.Value)
If Target.Cells(1, 2).Value < Date Then
Target.Cells(1, 2).Style = "Bad"
ElseIf Target.Cells(1, 2).Value > Date Then
Target.Cells(1, 2).Style = "Good"
ElseIf Target.Cells(1, 2).Value = Date Then
Target.Cells(1, 2).Interior.ColorIndex = 0
Target.Cells(1, 2).Font.ColorIndex = 1
End If
Target.Cells(1, 3).Value = DateAdd("d", 1, Target.Cells(1, 2).Value)
If Target.Cells(1, 3).Value < Date Then
Target.Cells(1, 3).Style = "Bad"
ElseIf Target.Cells(1, 3).Value > Date Then
Target.Cells(1, 3).Style = "Good"
ElseIf Target.Cells(1, 3).Value = Date Then
Target.Cells(1, 3).Interior.ColorIndex = 0
Target.Cells(1, 3).Font.ColorIndex = 1
End If
Application.EnableEvents = True
End If
End If
'Auto populate
If Not Intersect(Target, Range("N5:N16")) Is Nothing Then
If IsEmpty(Target) = True Then
'do nothing
ElseIf IsEmpty(Target) = False Then
Application.EnableEvents = False
Target.Cells(1, 2).Value = DateAdd("d", 1, Target.Value)
If Target.Cells(1, 2).Value < Date Then
Target.Cells(1, 2).Style = "Bad"
ElseIf Target.Cells(1, 2).Value > Date Then
Target.Cells(1, 2).Style = "Good"
ElseIf Target.Cells(1, 2).Value = Date Then
Target.Cells(1, 2).Interior.ColorIndex = 0
Target.Cells(1, 2).Font.ColorIndex = 1
End If
Application.EnableEvents = True
End If
End If
'Change to a late date to today or future date gives risk to need date
If Not Intersect(Target, Range("H5:V16")) Is Nothing Then
Application.EnableEvents = False
If PrevDate < Date Then 'here
If Target.Value = "-" Then
With Target
.Style = "Normal"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.BorderAround xlContinuous, xlThin
With .Font
.Name = "Calibri"
.Size = 11
End With
End With
ElseIf Target >= Date Then
Cells(Target.Row, "W").Style = "Neutral"
End If
End If
Application.EnableEvents = True
End If
End sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then 'allow multiple selection bc received error
Exit Sub
ElseIf Target.Count = 1 Then
If IsEmpty(Target) = True Then
PrevDate = Date
ElseIf IsDate(Target) = False Then
Exit Sub
ElseIf Target.Style = "Bad" Then
PrevDate = Target.Value
ElseIf Target.Style = "Good" Then
PrevDate = Target.Value
ElseIf Target.Style = "Normal" Then
PrevDate = Target.Value
End If
End If
End Sub