Sub Loc_DIC()
Dim du_lieu(), ket_qua(), Dic As Object, tmp As String
Dim sKey As String, i As Long, k As Long, n As Long
du_lieu = Sheet2.Range("D2", Sheet2.Range("D" & Rows.Count).End(3)).Resize(, 7).Value
ReDim ket_qua(1 To UBound(du_lieu), 1 To 13)
Set Dic = CreateObject("scripting.dictionary")
For i = 1 To UBound(du_lieu)
sKey = du_lieu(i, 5)
If Not IsEmpty(sKey) Then
tmp = UCase(du_lieu(i, 1))
If Not Dic.Exists(sKey) Then
k = k + 1
Dic.Add sKey, k
ket_qua(k, 1) = k
ket_qua(k, 2) = du_lieu(i, 5)
ket_qua(k, 3) = du_lieu(i, 7)
'If Left(du_lieu(i, 3), 1) <> "A" Then
If tmp = "EXPORT" Then
ket_qua(k, 6) = 1
ket_qua(k, 10) = du_lieu(i, 7)
ElseIf tmp = "IMPORT" Then
ket_qua(k, 7) = 1
ket_qua(k, 11) = du_lieu(i, 7)
ElseIf tmp = "RE-EXPORT" Then
ket_qua(k, 8) = 1
ket_qua(k, 12) = du_lieu(i, 7)
ElseIf tmp = "RE-IMPORT" Then
ket_qua(k, 13) = du_lieu(i, 7)
End If
'End If
Else
n = Dic.Item(sKey)
ket_qua(n, 3) = ket_qua(n, 3) + du_lieu(i, 7)
'If Left(du_lieu(i, 3), 1) <> "A" Then
If tmp = "EXPORT" Then
ket_qua(n, 6) = ket_qua(n, 6) + 1
ket_qua(n, 10) = ket_qua(n, 10) + du_lieu(i, 7)
ElseIf tmp = "IMPORT" Then
ket_qua(n, 7) = ket_qua(n, 7) + 1
ket_qua(n, 11) = ket_qua(n, 11) + du_lieu(i, 7)
ElseIf tmp = "RE-EXPORT" Then
ket_qua(n, 8) = ket_qua(n, 8) + 1
ket_qua(n, 12) = ket_qua(n, 12) + du_lieu(i, 7)
ElseIf tmp = "RE-IMPORT" Then
ket_qua(n, 9) = ket_qua(n, 9) + 1
ket_qua(n, 13) = ket_qua(n, 13) + du_lieu(i, 7)
End If
'End If
End If
End If
Next i
For i = 1 To k
ket_qua(i, 4) = "Export: " & ket_qua(i, 6) & "/Import: " & ket_qua(i, 7) & " /Re-Export: " & ket_qua(i, 8) & "/Re-Import: " & ket_qua(i, 9)
ket_qua(i, 5) = "Export: " & ket_qua(i, 10) & "/Import: " & ket_qua(i, 11) & " /Re-Export: " & ket_qua(i, 12) & "/Re-Import: " & ket_qua(i, 13)
Next
Sheet1.Range("C2").Resize(k, 5).Value = ket_qua
End Sub