Try this. Please remember that the days of the week on the RN Schedule and the tab names need to be the same.
Sub Penny110()
Dim ws As Worksheet
Set ws1 = Worksheets("RN Schedule")
LastRow = ws1.Cells(Rows.Count, "B").End(xlUp).Row
'clear names off the sheets
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "RN Schedule" Then
For k = 1 To 7 Step 3
ws.Range(ws.Cells(4, k), ws.Cells(ws.Cells(Rows.Count, k).End(xlUp).Row, k)).ClearContents
Next
End If
Next
For i = 3 To 9
Set ws2 = Worksheets(ws1.Cells(3, i).Value)
For j = 4 To LastRow
TheNames = ""
FullShift = True
With ws2.Range("A:H")
SearchFor = RTrim(ws1.Cells(j, i).Value)
If SearchFor <> "" Then
Set c = .Find(SearchFor)
If Not c Is Nothing Then
If c.Offset(0, -1).Value = "" Then
c.Offset(0, -1).Value = ws1.Cells(j, 2).Value
FullShift = False
Else
TheNames = TheNames & c.Offset(0, -1).Value & Chr(10)
FirstAdd = c.Address
Do
Set c = .FindNext(c)
If Not c Is Nothing Then
If c.Offset(0, -1).Value = "" Then
c.Offset(0, -1).Value = ws1.Cells(j, 2).Value
FullShift = False: Exit Do
Else
TheNames = TheNames & c.Offset(0, -1).Value & Chr(10)
End If
End If
Loop Until Not c Is Nothing And c.Address <> FirstAdd
End If
End If
If FullShift = True Then
ws2.Range("E" & Cells(Rows.Count, "E").End(xlUp).Row + 2).Value = _
"You are overbooked for " & SearchFor & " shift." & Chr(10) _
& "The following people are all booked for that shift:" & Chr(10) _
& TheNames & ws1.Cells(j, 2).Value
End If
End If
End With
Next
Next
End Sub
Bookmarks