Sub Bao_Cao_NXT()
Dim Dic As Object, sArr(), i As Long, Res(1 To 10000, 1 To 9), sh As Worksheet
Dim tmp As String, j As Long, k As Long, x As Long, shts(), n As Long
Set Dic = CreateObject("scripting.dictionary")
shts = Array("TON DK", "NHAP TK", "XKHO TK")
For n = LBound(shts) To UBound(shts)
Set sh = Sheets(shts(n))
If n = UBound(shts) Then
sArr = sh.Range("C3", sh.[C65536].End(3)).Resize(, 5).Value
Else
sArr = sh.Range("B3", sh.[B65536].End(3)).Resize(, 5).Value
End If
For i = 1 To UBound(sArr)
tmp = sArr(i, 1) & sArr(i, 2) & sArr(i, 3) & sArr(i, 4)
tmp = Replace(UCase(tmp), " ", "")
If Not Dic.exists(tmp) Then
k = k + 1
Dic.Add tmp, k
Res(k, 1) = k
For j = 1 To 4
Res(k, j + 1) = sArr(i, j)
Next
Res(k, n + 6) = sArr(i, 5)
Res(k, 9) = "=RC[-3]+RC[-2]-RC[-1]"
Else
x = Dic.Item(tmp)
Res(x, n + 6) = Res(x, n + 6) + sArr(i, 5)
End If
Next
Next
With Sheets("BAOCAO_X-N-T")
.[A4:F10000].ClearContents
.[A4].Resize(k, UBound(Res, 2)) = Res
End With
End Sub