Sub SangCong()
Dim Rws As Long, J As Long, Col As Integer, Ngay As Integer, Dg As Integer
Dim Rng As Range, sRng As Range
Dim Ma As String, MyAdd As String
Rws = [C9999].End(xlUp).Row
With Sheet1
Rws = 9 + .[C9999].End(xlUp).Row
Set Rng = .Range("C6").Resize(Rws)
For J = 11 To Rws Step 2
Ma = Cells(J, "C").Value: If Ma = "" Then Exit For
Cells(J, "E").Resize(2, 31).Value = Space(0) 'Xóa Du Liêu Da Có '
Set sRng = Rng.Find(Ma, , xlFormulas, xlWhole)
If Not sRng Is Nothing Then
Dg = sRng.Row
For Col = 5 To 66 Step 2
Ngay = Day(.Cells(4, Col))
If So(.Cells(Dg, Col).Value) And So(.Cells(Dg, Col + 1).Value) Then 'Làm Viêc Sáng '
If So(.Cells(1 + Dg, Col).Value) And So(.Cells(1 + Dg, Col + 1).Value) Then
Cells(J, "D").Offset(, Ngay).Value = "X" '& Làm Buôi Chiêu '
ElseIf (.Cells(1 + Dg, Col).Value = "CT" And .Cells(1 + Dg, Col + 1).Value = "CT") Then
Cells(J, "D").Offset(, Ngay).Value = "X/2"
Cells(1 + J, "D").Offset(, Ngay).Value = "CT" 'Chiêu Di Công Tác '
ElseIf (.Cells(1 + Dg, Col).Value = "x" And .Cells(1 + Dg, Col + 1).Value = "x") Then
Cells(J, "D").Offset(, Ngay).Value = "X/2"
End If
ElseIf (.Cells(Dg, Col).Value = "NP" And .Cells(Dg, Col + 1).Value = "NP") Then 'Nghi Phép Sáng '
If (.Cells(1 + Dg, Col).Value = "NP" And .Cells(1 + Dg, Col + 1).Value = "NP") Then
Cells(J, "D").Offset(, Ngay).Value = "NP"
ElseIf .Cells(1 + Dg, Col).Value = "PO" And .Cells(1 + Dg, Col + 1).Value = "PO" Then
Cells(J, "D").Offset(, Ngay).Value = "NP"
Cells(1 + J, "D").Offset(, Ngay).Value = "PO"
End If
ElseIf (.Cells(Dg, Col).Value = "CT" And .Cells(Dg, Col + 1).Value = "CT") Then 'Công Tác Sáng '
If (.Cells(1 + Dg, Col).Value = "CT" And .Cells(1 + Dg, Col + 1).Value = "CT") Then
Cells(J, "D").Offset(, Ngay).Value = "CT"
ElseIf So(.Cells(1 + Dg, Col).Value) And So(.Cells(1 + Dg, Col + 1).Value) Then
Cells(J, "D").Offset(, Ngay).Value = "CT"
Cells(1 + J, "D").Offset(, Ngay).Value = "X/2"
End If
End If
Next Col
End If
Next J
End With
End Sub