Transferring & Append New Data from one Workbook to Another Workbook (What's wrong with my code)

maximejeanlouis

New Member
Joined
Aug 19, 2015
Messages
7
Private Sub CommandButton1_Click()
'Declare variables
Dim I, LastRow, MLastRow

'Locate LastRow value
LastRow = ActiveSheet.Range("A" & Rows.count).End(xlUp).Row


For I = 2 To LastRow
If Cells(I, 1) > 0 Then
Range(Cells(I, 1), Cells(I, 30)).Select

Selection.Copy

Workbooks.Open Filename:="C:\Users\maxim\Desktop\6-27 Magento Process\Magento Invoices1.xlsm"

Dim p As Integer, q As Integer
p = Worksheets.count

For q = 1 To p
If ActiveWorkbook.Worksheets(q).Name = "Magento Invoice Master" Then
Worksheets("Magento Invoice Master").Select

End If
Next q

MLastRow = ActiveSheet.Cells(Rows.count, 1).End(xlUp).Offset(1, 0).Row

ActiveSheet.Cells(MLastRow, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save

'ActiveWOrkbook.Close

Application.CutCopyMode = False
End If

Next I

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
The VBA Code is Opening/Saving & Closing the receiving file after every Imported Line which makes it take forever. Can I append the entire block of new data without the program having to loop through each Row?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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