Copy data to the next row on a separate workbook

Jo4x4

Board Regular
Joined
Jan 8, 2011
Messages
136
Hi everybody,

I have six columns of data that I would like to copy to another workbook. The workbooks have the same column headings. The source sheet is monthly, and the destination sheet is a yearly total.
So I want anything that changes on the source sheet to be updated to the next available row in the destination sheet, either automatically or via a VBA button.

Any help will be appreciated

Thanks
Jo

Win XP, Office 2007
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
My big problem is getting the newest data to go to the next open row on the destination sheet.

Thanks
Jo

Win XP office 2007
 
Upvote 0
My big problem is getting the newest data to go to the next open row on the destination sheet.

Thanks
Jo

Win XP office 2007

Does this help?

Code:
Sub JO4X4()
Dim lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row

Sheets("Source").Range(Range("A2"), Range("F" & lr)).Copy Sheets("Destination").Range("A" & Rows.Count).End(xlUp)(2)

End Sub
 
Upvote 0
Thanks John, it works fine, but is there a way to "wake up" a closed destination file, or does it need to be open?

Thanks again.
Jo
 
Upvote 0
Thanks John, it works fine, but is there a way to "wake up" a closed destination file, or does it need to be open?

Thanks again.
Jo

I think it has too be open, but you can open, copy to, and then close it:

Code:
Sub JO4X4()
Dim lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row

Workbooks.Open Filename:="D:\Common\data\Destination.xls"

Workbooks("Source.xls").Sheets("Source").Range(Range("A2"), Range("F" & lr)).Copy Workbooks("Destination.xls").Sheets("Destination").Range("A" & Rows.Count).End(xlUp)(2)

Workbooks("Destination.xls").Close SaveChanges:=True

Workbooks("Source.xls").Activate


End Sub
 
Upvote 0
Hi John, it is giving me an error "subscript out of range"

I know preciously little about coding, but shouldn't the workbook be open before we try to find the next row?

Jo
 
Upvote 0
Hi John, it is giving me an error "subscript out of range"

I know preciously little about coding, but shouldn't the workbook be open before we try to find the next row?

Jo


Change this:

lr = Cells(Rows.Count, 1).End(xlUp).Row

To this:

lr = Workbooks("Source.xls").Sheets("Source").Cells(Rows.Count, 1).End(xlUp).Row
 
Upvote 0
Hi John,

It is working now. Stupid error on my side.

It is however giving me an error/warning that my destination sheet already contains a field called "date". When I then tell it to continue, it does everything perfectly.

Any ideas on what I can change to avoid the warning?

Thanks
Jo
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

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