Sub Loc_Hang_Hoa_test2()
Dim Dic As Object, arr(), kq()
Dim i As Long, lRow As Long, k As Long, ik As Long
Dim iKey As String
Set Dic = CreateObject("Scripting.Dictionary")
With Sheet1
lRow = .Range("D65000").End(xlUp).Row
arr = .Range("D1:E" & lRow).Value '"D1:E": Lay dòng tieu de
End With
For i = 2 To UBound(arr) 'i=2: Loai dong tieu de
iKey = arr(i, 1)
If iKey <> Empty Then Dic.Item(iKey & "|") = "" 'Loai dòng trong
Next i
With Sheet10
arr = .Range("A3:Q" & .Range("D65000").End(xlUp).Row).Value
End With
ReDim kq(1 To UBound(arr), 1 To 12)
For i = 1 To UBound(arr)
iKey = arr(i, 4)
If Not Dic.exists(iKey & "|") Then
If Not Dic.exists(iKey) Then
k = k + 1
Dic.Add iKey, k
kq(k, 1) = arr(i, 1)
kq(k, 2) = arr(i, 3)
kq(k, 3) = Format(arr(i, 1), "Tmm/yyyy")
kq(k, 4) = arr(i, 4)
kq(k, 5) = arr(i, 5)
kq(k, 6) = arr(i, 6)
End If
ik = Dic.Item(iKey)
'Chinh các lenh duoi theo dung cot
If Left(iKey, 2) = "BH" Then
kq(ik, 10) = kq(ik, 10) + arr(i, 10)
kq(ik, 12) = kq(ik, 12) + arr(i, 12)
Else
kq(ik, 9) = arr(i, 9) '????
End If
'******
End If
Next i
With Sheet1
If k Then
.Range("A" & lRow + 1).Resize(k, 12).Value = kq
MsgBox ("Da Copy " & k & " Dong Moi")
Else
MsgBox ("Khong Co Du Lieu Moi")
End If
End With
Set Dic = Nothing
End Sub