Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy row to another workbook

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I have the following code which copys the active row and pastes it to the next available row in another worksheet.

Code:
ActiveCell.EntireRow.Copy Destination:=Sheets("Archive").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues

How do I modify the code to copy the range A2:AB2 (rather than the active row) to another existing workbook stored in a particular folder.

Thanks
 
Provided that you want it to be pasted in the same location as the existing line of code:

Range("A2:B2").Copy Destination:=Sheets("Archive").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
 
I have modified my code to copy from active workbook to another work, however I am getting the 'subscript out of range error' on the Selection.Copy line.

The target workbook exists and there is an archive worksheet

Code:
Range("A2:AB2").Select
     Selection.Copy Destination:=Workbooks("Y:\People & Culture Europe\HR Operations\Customer Support Services\Support Hub\Team Folders\Andrew\LeaverArchive.xlsx").Sheets("Archive").Range("A" & Rows.Count).End(xlUp).Offset(1)

 
I don't think you can do all of this in one statement. You'll need to open the other spreadsheet first before you can edit it.
 
I'd do this...
Code:
Dim wbTO as workbook

'open the workbook 
Set wbTO = Workbooks.open("\People & Culture Europe\HR Operations\Customer Support Services\Support Hub\Team Folders\Andrew\LeaverArchive.xlsx")
 
'copy 'n' paste
Range("A2:AB2").Copy Destination:=wbTO.Sheets("Archive").Range("A" & wbTO.Sheets("Archive").Rows.Count).End(xlUp).Offset(1)


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top