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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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