Sub FAPBatchfile()
'Copies data from the current invoice in the INVOICE TEMPLATE sheet of
'this workbook to FAPBAtchfile.xls
Dim myRange As String
Dim Account As String
Dim InvDate As Date
Dim InvNum As Long 'invoice number
Dim InvSheet As Worksheet
Dim BatchSheet As Worksheet
Dim NextRow As Long 'the next available invoice row on the batch sheet
Dim oRow As Long 'row number on BatchSheet
Dim iRow As Long 'row number on InvSheet
Dim Cranges As Variant
Dim Pranges As Variant
Dim i As Long
Set InvSheet = ThisWorkbook.Worksheets("INVOICE TEMPLATE")
Workbooks.Open Filename:="G:\PUBS\PP-MS\INVOICES\FAPBatchfile.xls"
Set BatchSheet = ActiveWorkbook.Worksheets("FAPBatch File")
oRow = BatchSheet.UsedRange.Rows.Count + 1
iRow = 20
Do
Intersect(InvSheet.Range("B:B, F:F, C:C, D:D, J:J, K:K"), InvSheet.Rows(iRow)).Copy
Cranges = Array("B", "C", "D", "F", "J", "K")
Pranges = Array("E", "F", "G", "H", "I", "J")
For i = LBound(Cranges) To UBound(Cranges)
InvSheet.Cells(iRow, Cranges(i)).Copy
BatchSheet.Cells(oRow, Pranges(i)).PasteSpecial xlPasteValues
InvSheet.Range("E5").Copy 'Account
BatchSheet.Cells(oRow, "C").PasteSpecial xlPasteValues
InvSheet.Range("K2").Copy 'InvNum
BatchSheet.Cells(oRow, "A").PasteSpecial xlPasteValues
InvSheet.Range("F17").Copy 'InvDate
BatchSheet.Cells(oRow, "B").PasteSpecial xlPasteValues
InvSheet.Range("B6").Copy 'Customer name
BatchSheet.Cells(oRow, "D").PasteSpecial xlPasteValues
Next i
iRow = iRow + 1
oRow = oRow + 1
Loop Until IsEmpty(InvSheet.Cells(iRow, "B")) Or InvSheet.Cells(iRow, "B") = Q
InvSheet.Range("E5").Copy 'Account
BatchSheet.Cells(oRow, "C").PasteSpecial xlPasteValues
InvSheet.Range("K2").Copy 'InvNum
BatchSheet.Cells(oRow, "A").PasteSpecial xlPasteValues
InvSheet.Range("F17").Copy 'InvDate
BatchSheet.Cells(oRow, "B").PasteSpecial xlPasteValues
InvSheet.Range("B6").Copy 'Customer name
BatchSheet.Cells(oRow, "D").PasteSpecial xlPasteValues
InvSheet.Range("C38").Copy
BatchSheet.Cells(oRow, "F").PasteSpecial xlPasteValues
InvSheet.Range("D39").Copy
BatchSheet.Cells(oRow, "G").PasteSpecial xlPasteValues
InvSheet.Range("F38").Copy
BatchSheet.Cells(oRow, "H").PasteSpecial xlPasteValues
InvSheet.Range("K38").Copy
BatchSheet.Cells(oRow, "J").PasteSpecial xlPasteValues
InvSheet.Range("K44").Copy 'Invoice total
BatchSheet.Cells(oRow, "K").PasteSpecial xlPasteValues
InvSheet.Range("B38").Copy 'FMP Account Code
BatchSheet.Cells(oRow, "E").PasteSpecial xlPasteValues
Application.CutCopyMode = False
ActiveWorkbook.Close True 'save changes and close
End Sub