1

i have a workbook and im trying to copy the same row each time from A3:AP3 and paste it into the other closed workbook in the same range using the below code, it does work but it does it twice and it doesnt wanna add more rows in the destination workbook, im not sure what is the problem

Sub copytoclosed()
Dim destSht As Worksheet
Dim destwb  As Workbook
Dim copyrow, destlrow As Long
Workbooks.Open ("C:\Users\mgamal22\Desktop\sahar\New\DataBase.xlsx")
Set destSht = ActiveWorkbook.Worksheets("Sheet1")
With ThisWorkbook.Worksheets("Records")
    With .Range(.Range("A3:AP3"), .Range("A3:AP3").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
  • Why not `Set destwb = Workbooks.Open ("C:\Users\mgamal22\Desktop\sahar\New\DataBase.xlsx")` and `Set destSht = destwb.Worksheets("Sheet1")`? –  Sep 21 '17 at 16:15
  • 1
    I'm confused by *'it does work but it does it twice and it doesnt wanna add more rows in the destination workbook'*. That seems to contradict itself; either it does it twice (adding new rows) or it doesn't add new rows. Which is it? More importantly, is there always a value in the source's column A? If it is blank, then looking from the bottom up and offsetting one row down will catch the same row you used the last time. –  Sep 21 '17 at 16:20
  • i got it , the problem was with the range , Thanks Jeeped – Mustafa El-Gamal Sep 21 '17 at 16:39
  • Check this [out](https://stackoverflow.com/questions/19351832/copy-from-one-workbook-and-paste-into-another) – DaBeau96 Sep 21 '17 at 20:28

0 Answers0