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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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