View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default The best sub for last row / last column / last cell?

Ron,
I am not sure why you are falsely disparaging Chip's code, then posting
functionally identical code???

Your motivation escapes me???

Even if he had suggested xlDown, it seems you could have been less insulting
in your response particularly to someone who was posting excellent solutions
back when you were a newby asking for help.


Chip: LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row ' Column A
Ron: Lr = Sheets("sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1,
0).Row

Chip: LastCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column '
Row 1
Ron: Lc = Sheets("Sheet2").Range("IV1").End(xlToLeft).Offset (0, 1).Column

As I said, functionally, I don't see the difference (besides you add 1 to
the result which you explained).

--
Regards,
Tom Ogilvy




"Ron de Bruin" wrote in message
...
Chip's code will only work if all cells in A have data
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row ' Column A

See my site for another way
http://www.rondebruin.nl/copy1.htm

Text from my site:

You can also check one row or column to find the last cell with a value.

Lr = Sheets("sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row
This will give you the last row with data in Column A + 1 Row

Lc = Sheets("Sheet2").Range("IV1").End(xlToLeft).Offset (0, 1).Column
This will give you the last column with data in Row 1 + 1 column

Be aware that if you copy a range with also empty cells in it, It is
possible that the next time you copy to Sheets("Sheet2")some lines will be
overwritten.
Use the Functions to avoid this kind of problems.



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"justme" wrote in message
...

Chip,

This code is so short and simple. If it works for everything, then why
would people go through writing all sorts of functions to be called, etc.
to figure out the same thing?

Thanks