View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default The best sub for last row / last column / last cell?

Thanks for the info Tom

While working on other things I better not answering newsgroup postings the next time.

Sorry


--

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


"Tom Ogilvy" wrote in message ...
Ron,


Ron If you only want to know it for one column there is no problem
and that is what Chip Said:

Chip For a specific column or row, I always use code like

Also, the OP's question and Chip's answer had nothing to do with copying.
You added that scenario and then used it to "discredit" Chip's answer or at
least point it out as flawed as I read it???



Just as an added consideration, the lastrow function you have found in this
newgroup and documented on your site has limitations as well. If any
scenario is to be fantasized, then if column M (as an example) contained
unrelated data farther down the sheet, the function would return the
incorrect value for the last row in column A. Also, Find does not find a
cell containing the Null string "" entered when you do edit=copy and then
edit paste special, values for a cell containing the formula like
=If(true,"",""), which may or may not be desirable (end(xlup) does). So
while a robust solution, certainly not universal or for use without
understanding (undocumented on your site).


--
Regards,
Tom Ogilvy








"Ron de Bruin" wrote in message
...
Hi Chip/Tom

If you only want to know it for one column there is no problem
There are a few postings about last cells today so maybe I am confused <g

But if you copy a range to the last row + 1 in A and the range have empty
cell in A the next time
It will overwrite data.

That's why I say use the function

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


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.


Sorry, I have to much xml in my head . <vbg


--

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


"Chip Pearson" wrote in message
...
Chip's code will only work if all cells in A have data

I think you mean that if at least one cell in A has data, which I took as
an assumption. It will fail if A(Rows.Count) has data in it. But I NEVER
let data go down that far. It in no way requires that ALL the cells in A
have data. It will return the last row even if A has blanks interspersed
within the data. Unless A is completely empty or A(Rows.Count) has data,
it works fine.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"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