Sunday, 13 May 2018

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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...