Monday, November 11, 2019

excel vba - Other method than Select in VBA




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?


Answer



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

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...