Sub TestCN()
Dim iY As Long, iM As Long, iDate As Date, endR As Long, iDay As Long
Dim i As Long, iD As Long
Dim myRng As Range, rngR As Range
ActiveSheet.Select
Set myRng = Range("A7:D1000")
With myRng
Set rngR = .Find(What:="ghi chú", After:=myRng(1), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
End With
endR = rngR.Row 'dong co chu ghi chu'
'endR = Cells(65000, 2).End(xlUp).Row'
Range([k7], Cells(endR, "AP")).Font.ColorIndex = 0
iY = Year(Range("R1")): iM = Month(Range("R1")): iDay = Day(Range("R1"))
For i = 0 To 6
iD = Cells(7, 11 + (2 * i))
iDate = DateSerial(iY, iM, iD)
If Weekday(iDate) = 1 Then
If Cells(7, 11) = iDay Then
Range(Cells(9, 11 + (2 * i)), Cells(endR, 11 + (2 * i) + 1)).Font.ColorIndex = 3
Range(Cells(9, 11 + (2 * i) + 14), Cells(endR, 11 + (2 * i) + 1 + 14)).Font.ColorIndex = 3
Range(Cells(7, 11 + (2 * i)), Cells(7, 11 + (2 * i) + 1)).Font.ColorIndex = 3
Range(Cells(7, 11 + (2 * i) + 14), Cells(7, 11 + (2 * i) + 1 + 14)).Font.ColorIndex = 3
Else
Range(Cells(9, 9 + (2 * i)), Cells(endR, 9 + (2 * i) + 1)).Font.ColorIndex = 3
Range(Cells(9, 9 + (2 * i) + 14), Cells(endR, 9 + (2 * i) + 1 + 14)).Font.ColorIndex = 3
Range(Cells(8, 9 + (2 * i)), Cells(8, 9 + (2 * i) + 1)).Font.ColorIndex = 3
Range(Cells(8, 9 + (2 * i) + 14), Cells(8, 9 + (2 * i) + 1 + 14)).Font.ColorIndex = 3
End If
Exit For
End If
Next
Set myRng = Nothing
Set rngR = Nothing
End Sub