Te anexo la macro para los productos:
Sub InvoiceNumber()
'Por.Dante Amor
Set h1 = Sheets("datos")
Set h2 = Sheets("ej1")
Set h3 = Sheets("plantilla")
h2.Cells.Clear
'
j = 1
i = 2
n = 0
'
ant = h1.Cells(2, "F")
encabezado h1, h2, h3, i, j
For i = 2 To h1.Range("F" & Rows.Count).End(xlUp).Row
If ant <> h1.Cells(i, "f") Then
n = 0
encabezado h1, h2, h3, i, j
End If
ant = h1.Cells(i, "F")
If h1.Cells(i, "P") = "Duty Charges" Then
duty h1, h2, h3, i, j, n
Else
n = n + 1
productos h1, h2, h3, i, j, n
End If
Next
h2.Select
MsgBox "Proceso terminado", vbInformation, "PLANTILLA"
End Sub
Sub encabezado(h1, h2, h3, i, j)
'Por.Dante Amor
h3.Rows(1 & ":" & 3).Copy h2.Rows(j)
'
h2.Cells(j, "B") = h1.Cells(i, "F") 'invoice num
h2.Cells(j, "C") = h1.Cells(i, "J") 'invoice date
h2.Cells(j, "D") = h1.Cells(i, "G") 'CURRENCY
h2.Cells(j, "E") = h1.Cells(i, "AB") 'PO
h2.Cells(j, "F") = h1.Cells(i, "O") 'PAYMENT_TERM
j = j + 1
h2.Cells(j, "B") = h1.Cells(i, "A") 'BILL_TO_CUSTOMER_NAME
h2.Cells(j, "C") = h1.Cells(i, "Y") 'VAT NUMNER PURCHASING COMPANY
j = j + 1
h2.Cells(j, "B") = h1.Cells(i, "Z") 'SELLER
h2.Cells(j, "C") = h1.Cells(i, "AA") 'SELLER VAT
j = j + 1
End Sub
Sub productos(h1, h2, h3, i, j, n)
'Por.Dante Amor
h3.Rows(4 & ":" & 6).Copy h2.Rows(j)
'
h2.Cells(j, "B") = n 'consecutivo
h2.Cells(j, "C") = h1.Cells(i, "P") 'DESCRIPTION
j = j + 1
h2.Cells(j, "C") = h1.Cells(i, "K") 'QUANTITY_INVOICED
h2.Cells(j, "D") = h1.Cells(i, "M") 'EXTENDED_AMOUNT
h2.Cells(j, "K") = h1.Cells(i, "V") 'TAX_TOTAL
j = j + 2
End Sub
Sub duty(h1, h2, h3, i, j, n)
'Por.Dante Amor
h3.Rows(19 & ":" & 21).Copy h2.Rows(j)
'
h2.Cells(j, "B") = n 'consecutivo
'h2.Cells(j, "C") = h1.Cells(i, "P") 'DESCRIPTION
j = j + 1
h2.Cells(j, "C") = h1.Cells(i, "K") 'QUANTITY_INVOICED
h2.Cells(j, "D") = h1.Cells(i, "M") 'EXTENDED_AMOUNT
h2.Cells(j, "K") = h1.Cells(i, "V") 'TAX_TOTAL
j = j + 2
End Sub
Saludos.Dante Amor