3
x.Worksheets("Sheet1").Activate
Range("A65536").Select 
ActiveCell.End(xlUp).Select
lastrow = ActiveCell.Row 
Range("A2:A" & lastrow).Copy y.Worksheets("Sheet1").Range("a65536").End(xlUp).Offset(1, 0)
Range("B2:B" & lastrow).Copy y.Worksheets("Sheet1").Range("b65536").End(xlUp).Offset(1, 0)

I have read several places that using select is not recommended for copy pasting, and how can one do it without select?

Community
  • 1
  • 1
Meesha
  • 801
  • 1
  • 9
  • 27

2 Answers2

2

As an exact analog to your code:

lastRow = x.worksheets("Sheet1").range("A65536").end(xlup).row

Added because of comment recommending better practices:

with x.worksheets("Sheet1")
    lastRow = .Cells(.Rows.Count, 1).End(xlup).Row
end with
Sobigen
  • 2,038
  • 15
  • 23
2

You can set lastRow = x.worksheets("sheet1").Cells(Rows.Count, "A").End(xlUp).Row + 1

You need the first empty cell in the column, no the last one occupied

Jeanno
  • 2,769
  • 4
  • 23
  • 31