Option Explicit
Sub Loc()
Dim tkbChung, tenLop
Dim tam, lop
Dim kq
Dim rws, cls
Dim i, j, k, x, z, t
tkbChung = Sheet1.Range("C6:R35")
tenLop = Sheet1.Range("C5:R5")
rws = UBound(tkbChung)
cls = UBound(tkbChung, 2)
ReDim kq(1 To 31, 1 To 1)
With CreateObject("Scripting.Dictionary")
k = 0
For j = 1 To cls
lop = Split(tenLop(1, j), "(")(0)
For i = 1 To rws
If InStr(tkbChung(i, j), "-") Then
If tkbChung(i, j) <> "" Then
tam = Split(tkbChung(i, j), "-")
t = Trim(tam(1))
If .Exists(t) = False Then
k = k + 1
.Item(t) = k
If UBound(kq, 2) < k Then ReDim Preserve kq(1 To 31, 1 To k)
kq(1, k) = Trim(tam(1))
kq(i + 1, k) = tam(0) & "- " & lop
Else
kq(i + 1, .Item(t)) = tam(0) & "- " & lop
End If
End If
End If
Next i
Next j
End With
With Sheet3
.Range("C5").Resize(31, k).Clear
.Range("C5").Resize(31, k) = kq
.Range("C5").Resize(31, k).WrapText = 0
.Range("C5").Resize(31, k).Columns.AutoFit
.Range("C5").Resize(31, k).Borders.LineStyle = 1
End With
End Sub