View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Edwin Tam[_7_] Edwin Tam[_7_] is offline
external usenet poster
 
Posts: 94
Default 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