Copy and paste row to closed workbook

JKnight11

New Member
Joined
Mar 11, 2017
Messages
5
I want to be able to select a row and copy & paste it (With a command button) to a closed workbook that remains closed. The code below copies everything below a range. I just want to copy the row I have selected.

These are the lines that need to be changed:
With ThisWorkbook.Worksheets("Sheet1")
With .Range(.Range("A4:Q4"), .Range("A4:Q4").End(xlDown))
destSht.Cells(destSht.Rows.Count, 1).End(xlUp).Offset(1).Resize(.Rows.Count, .Columns.Count).Value = .Value


The full code:
Sub copytoarchive()
Dim destSht As Worksheet
Workbooks.Open ("C:\...\FileToCopyTo.xlsx")
Set destSht = ActiveWorkbook.Worksheets("Sheet3")
With ThisWorkbook.Worksheets("Sheet1")
With .Range(.Range("A4:Q4"), .Range("A4:Q4").End(xlDown))
destSht.Cells(destSht.Rows.Count, 1).End(xlUp).Offset(1).Resize(.Rows.Count, .Columns.Count).Value = .Value
End With
End With
destSht.Parent.Close True
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Something like this?

Code:
Sub copytoarchive()
Dim destwb As Workbook
Dim destSht, ws As Worksheet
Dim copyrow, destlrow As Long




Set destwb = Workbooks.Open("C:\...\FileToCopyTo.xlsx")


Set destSht = destwb.Worksheets("Sheet3")


Set ws = ThisWorkbook.Worksheets("Sheet1")


copyrow = ws.Cells(4, 1).End(xlDown).Row


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


destSht.Rows(destlrow + 1).Value = ws.Rows(copyrow).Value




destSht.Parent.Close True
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,381
Messages
6,136,228
Members
450,000
Latest member
jgp19

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