Phòng em có 13 người, cứ 2 người trực một ngày, lần lượt từ thứ hai đến thứ sáu. E đã search mạng và thấy bài của bác Hồng Việt bên webketoan nhưng khi chạy báo lỗi run-time error 9. Mong các bác giúp e hoàn thành nhiệm vụ làm lịch phân công với. Đoạn code của bác HongViet như thế này:
Sub Aut
pen()
Const STNhat = "<- Tröïc nhaät"
Dim SoNV As Integer: Dim NgayT As Variant
Dim ij As Integer: Dim Chu As String
1 '. Định Dòng Cuối:
Sheets("S1").Select: Range("A1").Select
Selection.End(xlDown).Select
SoNV = Selection.Row
NgayT = Date - 1: ij = 1
If Weekday(Date) = 2 Then NgayT = Date - 2
2 '. Định Ngày Cần Tìm:
Do
ij = 1 + ij
Chu = "E" & CStr(ij): Range(Chu).Select
If Len(ActiveCell.Value) < 2 Then Exit Do
If ActiveCell.Value = Date Then
Range("A2").Select: Exit Sub
End If
3 '. Định người trực hôm nay:
If ActiveCell.Value = NgayT Then
With Selection.Font
.FontStyle = "Normal"
End With
Chu = "D" & CStr(ij): Range(Chu).Select
ActiveCell.Value = ""
Chu = "D" & CStr(1 + ij)
If ij = SoNV Then Chu = "D2"
Range(Chu).Select: ActiveCell.Value = STNhat
Chu = "E" & CStr(1 + ij)
If ij = SoNV Then
Chu = "E3:E" & CStr(ij - 1): Range(Chu).Select
Selection.Value = ""
Chu = "E2"
End If
Range(Chu).Select: ActiveCell.Value = Date
With Selection.Font
.FontStyle = "Bold"
End With
End If
4'. Xoá dòng cuối khi ij=3
if ij=3 then
Range("E" & CStr(SoNV)).Select: ActiveCell.Value = ""
End If
Loop
Range("A3").Select
End Sub
Sub Aut

Const STNhat = "<- Tröïc nhaät"
Dim SoNV As Integer: Dim NgayT As Variant
Dim ij As Integer: Dim Chu As String
1 '. Định Dòng Cuối:
Sheets("S1").Select: Range("A1").Select
Selection.End(xlDown).Select
SoNV = Selection.Row
NgayT = Date - 1: ij = 1
If Weekday(Date) = 2 Then NgayT = Date - 2
2 '. Định Ngày Cần Tìm:
Do
ij = 1 + ij
Chu = "E" & CStr(ij): Range(Chu).Select
If Len(ActiveCell.Value) < 2 Then Exit Do
If ActiveCell.Value = Date Then
Range("A2").Select: Exit Sub
End If
3 '. Định người trực hôm nay:
If ActiveCell.Value = NgayT Then
With Selection.Font
.FontStyle = "Normal"
End With
Chu = "D" & CStr(ij): Range(Chu).Select
ActiveCell.Value = ""
Chu = "D" & CStr(1 + ij)
If ij = SoNV Then Chu = "D2"
Range(Chu).Select: ActiveCell.Value = STNhat
Chu = "E" & CStr(1 + ij)
If ij = SoNV Then
Chu = "E3:E" & CStr(ij - 1): Range(Chu).Select
Selection.Value = ""
Chu = "E2"
End If
Range(Chu).Select: ActiveCell.Value = Date
With Selection.Font
.FontStyle = "Bold"
End With
End If
4'. Xoá dòng cuối khi ij=3
if ij=3 then
Range("E" & CStr(SoNV)).Select: ActiveCell.Value = ""
End If
Loop
Range("A3").Select
End Sub