PDA

View Full Version : selecting last row / cell



grichey
06-25-2008, 06:40 AM
How do I select the last row or cell used? The rows are not continuous. ie there are blank rows randomly throughout data. Right now, I know only how to skip to the end of the continuous data but not how to find the last one.

Bob Phillips
06-25-2008, 06:56 AM
MsgBox Selection(Selection.Count).Row

grichey
06-25-2008, 07:30 AM
? Doesn't just return the row I have selected? Say I have data in rows 2:6 8:20 25:27.

I'm trying to figure out how to stop after code has run through line 27. But because this is variable, I can't simply say run till row 27.

Bob Phillips
06-25-2008, 07:32 AM
I just used selection as an example. As long as you have some way of marking the range, it should work.

Bob Phillips
06-25-2008, 07:36 AM
.

grichey
06-25-2008, 07:54 AM
Yea that's the thing. The only distinguishing thing for the last row is that from that row to row 65k there is no more data.
Ideas?

lucas
06-25-2008, 08:26 AM
Not sure I understand but maybe:
Sub y()
Dim FinalRow As Long
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
Rows(FinalRow).Select
End Sub

Edit: it looks in column A for the last data......

greymalkin
06-25-2008, 08:29 AM
you could mark the cell under the last cell with a "*" or some other value to search for...do you know the range of the data? Is the data being input manually or populated by a macro? If it's being populated by a macro you could capture the address of the last cell by creating a lastcell string variable and setting it to activecell.address(0,0). Or you could as Lucas suggested find a column that is populated entirely and find the last row from it.



The right answer is going to vary depending on your particular needs.

grichey
06-25-2008, 01:48 PM
I'll try lucas's idea tomorrow. The data is output as a .xls from some random accounting package. Unfortunately no column is populated entirely bc blank rows are used as seperators. You are correct I could manually hunt for something I put in the last cell but then it wouldn't be totally automated ;-)

lucas
06-25-2008, 02:22 PM
Unfortunately no column is populated entirely bc blank rows are used as seperators.

shouldn't matter as long as you have one column that consistantly has data in it. If there is data in that column and it is the last row it will be the row that is selected. These methods look from the bottom up for data so a blank row above will not matter.