Sub test()
Dim sh As Worksheet, NewSht As Worksheet, lrow As Long, data, result, i As Long, j As Long, production, igroup, article, n As Long, k As Integer, vl
Dim DestnSht As Worksheet, DestnCell As Range
If IsError(Evaluate("'Downloaded report'!A1")) Then Exit Sub
Set sh = Sheets("Downloaded report")
lrow = sh.UsedRange.Rows.Count
If lrow < 10 Then Exit Sub
data = sh.Range("b1:o" & lrow)
ReDim result(1 To lrow, 1 To 14)
result(1, 1) = data(2, 4)
result(2, 1) = data(4, 5)
result(3, 1) = "week#"
result(4, 1) = "Date"
result(3, 2) = data(8, 14)
result(4, 2) = Format(data(9, 14), "[$-10407]dd-mm")
For Each vl In Array(1, 6, 7, 9, 11, 12, 13)
k = k + 1
result(6, k) = data(9, vl)
Next
result(6, k + 1) = "Qty"
j = 6
For i = 10 To lrow
If data(i, 1) <> "" Then production = data(i, 1)
If data(i, 6) <> "" Then igroup = data(i, 6)
If data(i, 7) <> "" Then
article = data(i, 7)
j = j + 1
result(j, 1) = production
result(j, 2) = igroup
result(j, 3) = article
k = 3
For Each vl In Array(9, 11, 12, 13, 14)
k = k + 1
result(j, k) = data(i, vl)
Next
End If
Next
Application.ScreenUpdating = 0
Set NewSht = Sheets.Add
With NewSht
.Range("a1:h" & j) = result
.Range("a1,a3,a4,b4, a6:h6").Font.Bold = 1
.Range("a3:b4").HorizontalAlignment = xlCenter
.Range("a6:h" & j).Borders.LineStyle = xlContinuous
.Range("a6:h" & j).Columns.AutoFit
Set DestnSht = Workbooks("Master Data.xls").Sheets("Master Data")
With DestnSht
Set DestnCell = .Cells(.Rows.Count, 1).End(xlUp).Offset(1)
End With
.Range("a7:h" & j).Copy DestnCell.Offset(, 1)
With DestnCell.Resize(j - 6)
.Value = data(8, 14)
.Borders.LineStyle = xlContinuous
.HorizontalAlignment = xlCenter
End With
End With
Application.ScreenUpdating = 1
End Sub