03856me
Active Member
- Joined
- Apr 4, 2008
- Messages
- 297
I have a a rows of data that I need to separate and add to the last row (20 rows should end up as 60 rows). I need to split each row into 3 rows of data since the table export downloads all entries related to an invoice (Sub-Total, GST, and Total). Several fields will repeat on all three groups (InvoideID, InvoiceNumber, Total Amount), My code works well for both the Sub-Total and GST sections, but the Total code will not execute. Can someone help me understand what I am missing on the Total section.
VBA Code:
Sub TestCopy()
'=== Sub Total ================================================================================
Dim wb As Workbook
Set wb = ThisWorkbook
Dim wsTo As Worksheet
Set wsTo = wb.Sheets("test")
Dim wsFrom As Worksheet
Set wsFrom = wb.Sheets("Sheet1")
wsFrom.Range("B5:B999").Copy wsTo.Range("D6") 'VendorID
wsFrom.Range("C5:C999").Copy wsTo.Range("E6") 'InvoiceNumber
wsFrom.Range("E5:E999").Copy wsTo.Range("L6") 'Account
wsFrom.Range("J5:J999").Copy wsTo.Range("F6") 'Total Amount
wsFrom.Range("F5:F999").Copy wsTo.Range("M6") 'Sub-Total Amount
'=== GST ================================================================================
Dim LastRow As Long
LastRow = Range("D" & Rows.Count).End(xlUp).Row
wsFrom.Range("B5:B999").Copy wsTo.Range("D" & LastRow) 'VendorID
wsFrom.Range("C5:C999").Copy wsTo.Range("E" & LastRow) 'InvoiceNumber
wsFrom.Range("L5:L999").Copy wsTo.Range("L" & LastRow) 'Account
wsFrom.Range("J5:J999").Copy wsTo.Range("F" & LastRow) 'Total Amount
wsFrom.Range("G5:G999").Copy wsTo.Range("M" & LastRow) 'GST Amount
'=== TOTAL ================================================================================
wsFrom.Range("B5:B999").Copy wsTo.Range("D" & LastRow) 'VendorID
wsFrom.Range("C5:C999").Copy wsTo.Range("E" & LastRow) 'InvoiceNumber
wsFrom.Range("D5:D999").Copy wsTo.Range("L" & LastRow) 'Account
wsFrom.Range("J5:J999").Copy wsTo.Range("F" & LastRow) 'Total Amount
wsFrom.Range("G5:G999").Copy wsTo.Range("M" & LastRow) 'Invoice Total
End Sub