Sub ChuyenBangDuLieu()
Dim Cls As Range, Rng As Range, Rhd As Range, Cll As Range, WF As Object
Dim Rws As Long, W As Long, Tmr As Double, STT As Long
Dim MaNVL As String
Set WF = Application.WorksheetFunction: Tmr = Time()
With Sheet5
Rws = .[B5].CurrentRegion.Rows.Count
Set Rng = .Range(.[j3], .[j3].End(xlToRight))
ReDim Arr(1 To Rws * Rng.Cells.Count, 1 To 14)
Sheets("XKho").[A2].Resize(Rws * Rng.Cells.Count, 14).Value = ""
For Each Cls In Rng 'Duyêt Theo Sô Hóa Don '
Set Rhd = Cls.Offset(2).Resize(Rws)
STT = STT + 1
For Each Cll In Rhd 'Duyêt Theo Mã Nguyên Vât Liêu '
MaNVL = .Cells(Cll.Row, "B").Value
If MaNVL = "" Then Exit For
If Cll.Value > 0 Then
W = W + 1: Arr(W, 1) = STT
Arr(W, 3) = Cls.Value:
Arr(W, 2) = WF.VLookup(Cls.Value, Sheets("Sheet1").Range("B1:D900"), 2, False)
Arr(W, 4) = WF.VLookup(Cls.Value, Sheets("Sheet1").Range("B1:D900"), 3, False)
Arr(W, 5) = MaNVL
Arr(W, 6) = .Cells(Cll.Row, "C").Value: Arr(W, 7) = .Cells(Cll.Row, "D").Value
Arr(W, 8) = .Cells(Cll.Row, "E").Value: Arr(W, 9) = Cll.Value
End If
Next Cll
Next Cls
If W Then
Sheets("XKho").[A2].Resize(W, 14).Value = Arr()
End If
Sheets("XKho").Select: [P1].Value = Timer() - Tmr
MsgBox "Xong Rôi!", , "GPE.COM Xin Chào!"
End With
End Sub