Macro - Auto select to last active cell


Posted by giohess on March 29, 2001 3:46 PM

I have a macro set up that will reformat text files for reports. I have to specify the range since the text files vary in size. I would like my macro to go from A2 to the last active cell and select it. Is there a way to do this without specifying the range?



Posted by Dave Hawley on March 29, 2001 5:46 PM

Hi giohess

By ActiveCell I assume you mean the last cell containing data.

You could use:

Sheets("sheet1").UsedRange.Select

But this will also include a cell with ANY type of format as the last cell, so the prefered way is:

Sub AllData()
Dim LastRow As Long
Dim LastColumn As Integer

LastRow = Cells.Find(What:="*", After:=[A1], _
searchorder:=xlByRows, searchdirection:=xlPrevious).Row

LastColumn = Cells.Find(What:="*", After:=[A1], _
searchorder:=xlColumns, searchdirection:=xlPrevious).Column

Range("A2", Cells(LastRow, LastColumn)).Select

End Sub


Dave
OzGrid Business Applications