Shweta
Well-known Member
- Joined
- Jun 5, 2011
- Messages
- 514
Hi All,
Please help me out with a VBA code to select all the data on a worksheet.
I am using the following code:
Sheets(1).Select
Range("A1").Select
On Error Resume Next
mylastrow = Cells.Find("*", [a1], , , xlByRows, xlPrevious).Row
mylastcol = Cells.Find("*", [a1], , , xlByColumns, xlPrevious).Column
mylastcell = Cells(mylastrow, mylastcol).Address
myrange = "A2:" & mylastcell
Range(myrange).Select
Selection.Copy
I am not getting what is the problem with this code. It works sometimes and sometimes not.
Please help me out on this.
Thanks!
Regards,
Shweta
Please help me out with a VBA code to select all the data on a worksheet.
I am using the following code:
Sheets(1).Select
Range("A1").Select
On Error Resume Next
mylastrow = Cells.Find("*", [a1], , , xlByRows, xlPrevious).Row
mylastcol = Cells.Find("*", [a1], , , xlByColumns, xlPrevious).Column
mylastcell = Cells(mylastrow, mylastcol).Address
myrange = "A2:" & mylastcell
Range(myrange).Select
Selection.Copy
I am not getting what is the problem with this code. It works sometimes and sometimes not.
Please help me out on this.
Thanks!
Regards,
Shweta