Sub Tonghopsolieu()
Dim Solieu As Variant
Dim Tonghop() As String
Dim i As Long, j As Long, k As Long
Solieu = Sheet1.Range("a2", Sheet1.Range("d4").End(xlDown))
ReDim Tonghop(1 To UBound(Solieu), 1 To UBound(Solieu, 2))
For i = 1 To UBound(Solieu, 2)
Tonghop(1, i) = Solieu(1, i)
Next i
For i = 2 To UBound(Solieu)
If Solieu(i, 2) <> "" Then
j = CLng(Right(Solieu(i, 2), 4)) + 1
If InStr(Tonghop(j, 1), Solieu(i, 1)) = 0 Then
If Tonghop(j, 1) = "" Then
Tonghop(j, 1) = Solieu(i, 1)
Tonghop(j, 3) = Solieu(i, 3)
Else
Tonghop(j, 1) = Tonghop(j, 1) & "/" & Solieu(i, 1)
Tonghop(j, 3) = Tonghop(j, 3) & "/" & Solieu(i, 3)
End If
End If
Tonghop(j, 2) = Solieu(i, 2)
Tonghop(j, 4) = Solieu(i, 4)
If k < j Then k = j
End If
Next i
Sheet1.Range("f3").Resize(k + 1, UBound(Tonghop, 2)) = Tonghop
End Sub