selecting multiple rows within a Macro
Ronald,
Looks like you had several typos in this:
ActiveWorksheet should be ActiveSheet,
UsedRange probably isn't a good choice for a variable name. (caused me an
error)
UsedRange.Rows and UsedRange.Columns are objects. Think you want
UsedRange.Rows.count and UsedRange.Columns.count
You have your math backwards
Should be UsedRange.Columns.count - UsedRange.Column + 1
Anyway, here is a possible revision:
Sub Tester1()
Dim uRange As Range, LastColumn As Long, LastRow As Long
Set uRange = ActiveSheet.UsedRange
LastColumn = uRange.Columns.Count - uRange.Column + 1
LastRow = uRange.Rows.Count - uRange.Row + 1
ActiveSheet.Range(ActiveCell, Cells(LastRow, LastColumn)).Select
End Sub
This one is a little less typing.
Sub Tester2()
Dim uRange As Range
Set uRange = ActiveSheet.UsedRange
ActiveSheet.Range(ActiveCell, uRange(uRange.Count)).Select
End Sub
--
Regards,
Tom Ogilvy
Ronald Dodge wrote in message
...
Maybe you could try something like:
Dim UsedRange as Range, LastColumn as Long, LastRow as Long
Set UsedRange = ActiveWorksheet.UsedRange
LastColumn = UsedRange.Column + UsedRange.Columns - 1
LastRow = UsedRange.Row + UsedRange.Rows - 1
ActiveWorksheet.Range(ActiveCell,Cells(LastRow,Las tColumn)).Select
This is what I found in the help file under the Worksheet Object list of
Properties.
--
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Eric Dreshfield" wrote in message
...
How can I write the code to select multiple rows in a
Macro ? I want the macro to mimic the following
keystrokes:
Ctrl-Shift-End
to select a range of cells from where the cursor currently
resides to the end of where data exists.
I can't seem to figure out how to accomplish that.
Thanks !!
|