Sub Gop_Dulieu()
Dim sArr1(), sArr2(), Dic As Object, Res()
Dim i As Long, k As Long, tmp As String, sArr(), n As Long, x As Long
Set Dic = CreateObject("scripting.dictionary")
With Sheets("DL1")
sArr1 = .Range("B5", .Range("B" & Rows.Count).End(3)).Resize(, 9).Value
End With
With Sheets("DL2")
sArr2 = .Range("B5", .Range("B" & Rows.Count).End(3)).Resize(, 9).Value
End With
sArr = Array(sArr1, sArr2)
ReDim Res(1 To (UBound(sArr1) + UBound(sArr2)), 1 To 9)
For n = LBound(sArr) To UBound(sArr)
For i = 1 To UBound(sArr(n))
If sArr(n)(i, 1) <> Empty Then
tmp = sArr(n)(i, 1) & sArr(n)(i, 2) & sArr(n)(i, 3) & sArr(n)(i, 4) & sArr(n)(i, 5) & sArr(n)(i, 6)
tmp = Replace(LCase(tmp), " ", "")
If Not Dic.exists(tmp) Then
k = k + 1
Dic.Add tmp, k
Res(k, 1) = sArr(n)(i, 1)
Res(k, 2) = sArr(n)(i, 2)
Res(k, 3) = sArr(n)(i, 3)
Res(k, 4) = sArr(n)(i, 4)
Res(k, 5) = sArr(n)(i, 5)
Res(k, 6) = sArr(n)(i, 6)
Res(k, n + 7) = sArr(n)(i, 8) 'lay so luong
Res(k, 9) = sArr(n)(i, 9) 'thanh tien
Else
x = Dic.Item(tmp)
Res(x, n + 7) = Res(x, n + 7) + sArr(n)(i, 8) 'cong don so luong
Res(x, 9) = Res(x, 9) + sArr(n)(i, 9) 'cong don thanh tien
End If
End If
Next
k = k + 1
Next
Sheets("GOP").Range("B5").Resize(k, 9) = Res 'gan ket qua xuong sheet
End Sub