Saturday, September 1, 2007

Select Data Range

This is a useful when you need to select the whole range of data to copy to another sheet (especially a large range).

Sub SelAllData()

Application.ScreenUpdating = False
Dim myLastRow As Long
Dim myLastColumn As Long
On Error Resume Next
myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
myLastColumn = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
myLastCell = Cells(myLastRow, myLastColumn).Address
myRange = "a1:" & myLastCell
Application.ScreenUpdating = True

End Sub

No comments:

Post a Comment