Separate & Duplicate table

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
 

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top