Gửi bạn, trong file mẩu của mình có 2sheet : "NKGN" và "BCTK" mình muốn lấy dữ liệu cột : mã bao,mã hàng, loại vàng từ sheet "NKGN" sang sheet "BCTK" và điều kiện lọc là cột A của sheet "NKGN" những mã trùng lặp thì lấy 1 lần. Cột mã bao lấy sang sheet "BCTK" sắp xếp theo thứ tự tăng dần và theo nhóm loại vàng. Mong nhận được hướng dẫn của các bạn.
Sub rep()
Dim i As Long, j As Long, K As Long
Dim K1 As Long
Dim ArrNguon()
Dim ArrDich()
Dim Arr_MH()
Dim Dongcuoi As Long
Dim Dic_MH As Object
Dongcuoi = Sheet10.Range("A60000").End(xlUp).Row
ArrNguon = Sheet10.Range("A6:E" & Dongcuoi)
ReDim Arr_MH(1 To UBound(ArrNguon, 1), 1 To 4)
ReDim Arr_Ngay(1 To 1, 1 To UBound(ArrNguon, 1))
Sheet11.Range("a9:d60000").ClearContents
Set Dic_MH = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(ArrNguon, 1)
If Trim(ArrNguon(i, 1)) <> "" Then 'Trim loc bo khoang trong, cot 1 Ma'
If Not Dic_MH.Exists(ArrNguon(i, 1)) Then
K = K + 1
Dic_MH.Add ArrNguon(i, 1), K
Arr_MH(K, 1) = K
Arr_MH(K, 2) = ArrNguon(i, 3)
Arr_MH(K, 3) = ArrNguon(i, 4)
Arr_MH(K, 4) = ArrNguon(i, 5)
End If
End If
Next
Sheet11.Range("B9").Resize(K, 3).NumberFormat = "@"
Sheet11.Range("A9").Resize(K, 4) = Arr_MH
End Sub
Sub rep()
Dim i As Long, j As Long, K As Long
Dim K1 As Long
Dim ArrNguon()
Dim ArrDich()
Dim Arr_MH()
Dim Dongcuoi As Long
Dim Dic_MH As Object
Dongcuoi = Sheet10.Range("A60000").End(xlUp).Row
ArrNguon = Sheet10.Range("A6:E" & Dongcuoi)
ReDim Arr_MH(1 To UBound(ArrNguon, 1), 1 To 4)
ReDim Arr_Ngay(1 To 1, 1 To UBound(ArrNguon, 1))
Sheet11.Range("a9:d60000").ClearContents
Set Dic_MH = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(ArrNguon, 1)
If Trim(ArrNguon(i, 1)) <> "" Then 'Trim loc bo khoang trong, cot 1 Ma'
If Not Dic_MH.Exists(ArrNguon(i, 1)) Then
K = K + 1
Dic_MH.Add ArrNguon(i, 1), K
Arr_MH(K, 1) = K
Arr_MH(K, 2) = ArrNguon(i, 3)
Arr_MH(K, 3) = ArrNguon(i, 4)
Arr_MH(K, 4) = ArrNguon(i, 5)
End If
End If
Next
Sheet11.Range("B9").Resize(K, 3).NumberFormat = "@"
Sheet11.Range("A9").Resize(K, 4) = Arr_MH
End Sub
File đính kèm
Lần chỉnh sửa cuối: