ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   append data to other workbook (https://www.excelbanter.com/excel-programming/333240-append-data-other-workbook.html)

Todd

append data to other workbook
 
Hi,

I'm trying to write a macro that copies data from one sheet to another, but
i need it to append to row under the last row.
E.g. If i have a sheet with 10 rows filled with data, i want the next time i
want to append data in the sheet to start at the 11th row



R.VENKATARAMAN

append data to other workbook
 
try something like this

range("a1").end(xldown).offset(1,0)

it will go the last row plus one row.

--------------------------------
Todd wrote in message
...
Hi,

I'm trying to write a macro that copies data from one sheet to another,

but
i need it to append to row under the last row.
E.g. If i have a sheet with 10 rows filled with data, i want the next time

i
want to append data in the sheet to start at the 11th row





Edwin Tam[_7_]

append data to other workbook
 
To use the macro below, you first need to have the cells you want to "copy"
selected. Then run the macro.

In the macro, you also need to define the "target_book" and "target_sheet".
These are the file name of the target workbook and name of the target
worksheet to which you want to send the data.


Sub copy_data()
Dim target_book As String
Dim target_sheet As String

'define the sheet to which you want to send data
target_book = "Book2.xls"
target_sheet = "Sheet2"

On Error GoTo copy_err
With Workbooks(target_book).Worksheets(target_sheet).Ra nge("A1").CurrentRegion
If .Rows.Count = 1 And .Cells(1).Formula = "" Then
Selection.Copy .Range("A1")
Else
Selection.Copy .Range("A1").Offset(.Rows.Count, 0)
End If
End With
Exit Sub
copy_err:
MsgBox ("Error copying to the target location."), vbExclamation
End Sub


Regards,
Edwin Tam

http://www.vonixx.com



"Todd" wrote:

Hi,

I'm trying to write a macro that copies data from one sheet to another, but
i need it to append to row under the last row.
E.g. If i have a sheet with 10 rows filled with data, i want the next time i
want to append data in the sheet to start at the 11th row




All times are GMT +1. The time now is 10:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com