Sub RestSchedule()
Dim lRow As Long
Dim i As Long
Dim j As Long
Dim vArr(1 To 48)
Dim Wh As Long
Dim BeforeMidnight As Long
Dim AfterMidnight As Long
lRow = 32
For i = 2 To lRow
If Cells(i, "A") Like "[MADN]" Then
If Cells(i, "B").Value > 0 Then
Erase vArr
Wh = Cells(i, "B").Value
For j = 1 To 48
vArr(j) = "X"
Next j
Select Case UCase(Cells(i, "A").Value)
Case "M"
For j = 1 To Wh * 2
vArr(j) = Empty
Next j
Case "A"
For j = 25 - IIf(Wh - 12 > 0, (Wh - 12) * 2, 0) To Application.Min(48, Wh * 2 + 24)
vArr(j) = Empty
Next j
Case "D"
For j = 13 To 12 + Wh * 2
vArr(j) = Empty
Next j
Case "N"
BeforeMidnight = Application.Min(6, Wh) * 2
AfterMidnight = Wh * 2 - BeforeMidnight
For j = 1 To 48
If j > 0 And j <= AfterMidnight Or j >= 37 And j <= 36 + BeforeMidnight Then
vArr(j) = Empty
End If
Next j
End Select
Cells(i, "C").Resize(, 48).Value = vArr
End If
End If
Next i
End Sub