Option Explicit
Dim lRow As Long
Dim Rng As Range, RngCr As Range, RngDes As Range
Sub LapDSach()
' Macro recorded 4/7/2008 by Sa_DQ (GPE.COM);'
Dim DienHS As String, Xh As String
Dim DesRow As Long
Xh = Chr(10) & Chr(13): Sheets("Ca Nam").Select
lRow = Range("A65432").End(xlUp).Row
Set Rng = Range("A2:U" & lRow): Set RngDes = Range("W5:AB5")
DienHS = "1: Luu Ban;" & Xh & "2: Thi Lai;" & Xh & "3: Ren Hanh Kiem;"
Application.ScreenUpdating = False
DienHS = InputBox(DienHS, "BAN CAN LAP DANH SACH NAO?", "A")
DienHS = UCase$(DienHS)
Select Case DienHS
Case "A"
Range("Z2") = "Y": Range("AA2") = "Y"
DesRow = 8: Sheets("LbTlRhk").Range("C8:C20").ClearContents
Case "B"
Range("Z2") = "<>Y": Range("AA2") = "Y"
DesRow = 24: Sheets("LbTlRhk").Range("C24:C35").ClearContents
Case "C"
Range("Z2") = "Y": Range("AA2") = "<>Y"
DesRow = 40: Sheets("LbTlRhk").Range("C40:C49").ClearContents
End Select
Set RngCr = Range("W1:AB2")
Rng.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=RngCr, _
CopyToRange:=RngDes, Unique:=False
2 'Chon Trong Cac Mon Kiem Tra Lai'
Dim RowTL As Long, jW As Long, JZ As Long
Dim MonThi As String, HoTen As String
Dim DemMon As Byte '<<== New'
RowTL = Range("X65432").End(xlUp).Row
If DienHS = "B" Then
For jW = 6 To RowTL
With Cells(jW, 24)
HoTen = .Value
For JZ = 3 To lRow
If Cells(JZ, 2) = HoTen Then
Set Rng = Cells(JZ, 2).Offset(, 1).Resize(1, 13)
For Each RngDes In Rng
5 If RngDes < 5 And RngDes <> "" Then
6 DemMon = 1 + DemMon
7 MonThi = MonThi & Cells(2, RngDes.Column) & "=" & RngDes & "; "
End If
Next RngDes
8 .Offset(, 5) = DemMon & " môn: " & MonThi
MonThi = ""
End If
Next JZ
End With
Next jW
End If
Range("X6:X" & RowTL).Copy Destination:=Sheets("LbTlRhk").Range("C" & DesRow)
If DienHS = "B" Then _
Range("AC6:AC" & RowTL).Copy Destination:=Sheets("LbTlRhk").Range("E" & DesRow)
Set Rng = Nothing
Set RngCr = Nothing: Set RngDes = Nothing
Sheets("LbTlRhk").Select: Range("C" & DesRow).Select
End Sub