Finding the last row of a contiguous range

  • Thread starter Thread starter RalphH
  • Start date Start date
R

RalphH

Is there a better way of finding the last row of a contiguous range
than:

Selection.End(xlDown).Select
 
one way, as an example

dim lastrow as long
lastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row

range("A1:A" & lastrow).copy
 
sorry, forgot something:

dim lastrow as long
dim ws as worksheet

Set ws = Worksheets("Sheet1")
lastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row

range("A1:A" & lastrow).copy
 
Oh yes there is...

Dim LastRow as Long

LastRow = yourSheetName.Cells.Find(What:="*", After:=[A1],
SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

....Its my favorite... Enjoy!
 
There are a myriad of situations that would make your suggestion return the
wrong answer for the question asked. Besides that, what makes you think it
is better.

--
Regards,
Tom Ogilvy

elachowitz said:
Oh yes there is...

Dim LastRow as Long

LastRow = yourSheetName.Cells.Find(What:="*", After:=[A1],
SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

...Its my favorite... Enjoy!


Is there a better way of finding the last row of a contiguous range
than:

Selection.End(xlDown).Select
 
Well the original statement was for [Selection.End(xlDown).Select]
which does not fully encapsulate connecting without a break (which is
what I read the question to be)

The reason I like it… the absolute last row of a sheet will allow for
looping statements to evaluate all of your ranges/cells in question…

In addition, you will not need to consistently save your sheet using
my statement as you would with lets say
[Cells.SpecialCells(xlCellTypeLastCell).Row] or some other methods.
Just personal preference, nothing more.
 
Well the original statement was for [Selection.End(xlDown).Select]
which does not fully encapsulate connecting without a break (which is
what I read the question to be)

The reason I like it… the absolute last row of a sheet will allow for
looping statements to evaluate all of your ranges/cells in question…

In addition, you will not need to consistently save your sheet using
my statement as you would with lets say
[Cells.SpecialCells(xlCellTypeLastCell).Row] or some other methods.
Just personal preference, nothing more.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top