Sub Test90()
Dim myRangeA As Long
Dim myRangeB As Long
Dim Shift As String
Dim i As Long
Dim e As Long
Dim myDate As Date
Dim myDate2 As Date
myRangeA = Sheets("Data").Cells(Rows.Count).End(xlToLeft).Row
myRangeB = Sheets("Charts").Cells(Rows.Count).End(xlToLeft).Row
For i = 2 To myRangeA
myDate = Sheets("Data").Range("AD" & i).Value
If Hour(myDate) >= 5 And Hour(myDate) <= 17 Then
If Hour(myDate) = 17 And Minute(myDate) = 0 Then
Shift = "Day"
ElseIf Hour(myDate) <> 17 Then
Shift = "Day"
End If
End If
If Hour(myDate) <= 4 Or Hour(myDate) >= 17 Then
If Hour(myDate) = 17 And Minute(myDate) > 0 Then
Shift = "Night"
ElseIf Hour(myDate) <> 17 Then
Shift = "Night"
End If
End If
For e = 2 To myRangeB
myDate2 = Sheets("Charts").Range("A" & e).Value
If Month(myDate2) = Month(myDate) And Day(myDate2) = Day(myDate) And Year(myDate2) = Year(myDate) Then
If Shift = "Day" Then
Sheets("Data").Range("BO" & i).Value = Sheets("Charts").Range("B" & e).Value
ElseIf Shift = "Night" Then
Sheets("Data").Range("BO" & i).Value = Sheets("Charts").Range("C" & e).Value
End If
Exit For
End If
Next e
Next i
End Sub