Option Explicit: Const SHS As Integer = 99[b]
Function HocLop(IDex As String, Optional DaHoc As Boolean) As String[/b]
Dim Rng As Range, AllRng As Range
Dim ij As Integer, Hoc As String
Set AllRng = Sheets("Sheet2").Range("A3:A" & SHS)
ij = 2
For Each Rng In AllRng
ij = ij + 1
If Rng.Value = IDex Then
Set AllRng = Range("E" & ij & ":N" & ij)
Exit For
End If
Next Rng
If DaHoc = True Then Hoc = "X"
ij = 0
For Each Rng In AllRng
ij = ij + 1
If UCase$(Rng.Value) = Hoc Then
HocLop = HocLop & "L" & CStr(ij) & ","
End If
Next Rng
Set AllRng = Nothing
[b]End Function[/b]