Option Explicit
Sub TKB()
Dim i&, j&, lr&, t&, k&, m&, R, C&
Dim Arr(), KQ
Dim Dic As Object, Key
Dim Sh As Worksheet, Ws As Worksheet
Set Sh = Sheets("TKB GV")
lr = Sh.Cells(Rows.Count, 3).End(xlUp).Row
Arr = Sh.Range("C3:CT" & lr).Value
R = UBound(Arr): C = UBound(Arr, 2)
ReDim KQ(1 To C, 1 To 4)
For j = 2 To C
t = t + 1
KQ(t, 1) = Arr(1, j)
Set Dic = CreateObject("Scripting.Dictionary")
For i = 2 To R
If Arr(i, j) <> Empty Then
k = k + 1: KQ(t, 4) = k
Key = Arr(i, j)
End If
If Not Dic.Exists(Key) Then
m = m + 1: Dic.Add (Key), m
If InStr(1, Key, "_") = 0 Then
If KQ(t, 2) = Empty Then KQ(t, 2) = Key Else KQ(t, 2) = KQ(t, 2) & ", " & Key
Else
If KQ(t, 3) = Empty Then KQ(t, 3) = Key Else KQ(t, 3) = KQ(t, 3) & ", " & Key
End If
End If
Next i
k = 0: m = 0: Set Dic = Nothing:
Key = Empty ' ===== them dong này=======
Next j
If t Then
Set Ws = Sheet2
Ws.Range("A2").Resize(1000, 4).ClearContents
Ws.Range("A2").Resize(t, 4) = KQ
End If
MsgBox " Xong"
End Sub