View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
justme justme is offline
external usenet poster
 
Posts: 68
Default The best sub for last row / last column / last cell?

Hello All,

Actually, I did mean code. I have not had much sleep lately.

Here is what I am getting at, Tom: I have seen different ways to find the
last row or last column or last cell, using find(What) or xllastcell or
usedRange or rows.count. Many of them rely on a certain row or column to be
named, or some other condition. Some of them require calling functions and
some don't. Some go down to row 65536 and back up again. Ron's post above is
yet another. But I would just like to know which is the most reliable to use
on any worksheet, sight unseen, whether you're not sure which column is the
longest, if rows are missing, if a cell here or there is gone or if there are
large gaps in data areas, what would be the most reliable, most succinct code
(and hopefully doesn't take too long).

I just want to find the best, all-inclusive way so I don't have to take
everything into account about any particular worksheet when I want to find a
"last". So I am looking for expert opinions.

I think the following sub posted by you, Tom may be the answer, but I don't
know if there are things it may not take into account, and that's why I
started this thread.

Dim RealLastRow As Long
Dim RealLastColumn As Long
Range("A1").Select
'On Error Resume Next
RealLastRow = _
Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
RealLastColumn = _
Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
Cells(RealLastRow, RealLastColumn).Select ' find last row




I really appreciate all the posts here and the others I have found. I copy
many of them to my notebook.