Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / June 2007

Tip: Looking for answers? Try searching our database.

Best way to find row number of last row containing data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Pollard - 18 Jun 2007 00:36 GMT
I would like to know the best way of find the row number of the last row
containg data in a worksheet.
Searching through newsgroups and web sites I found the first option (which
is commented out below)
but this is column specific i.e. it only works if the last used cell in the
worksheet is in column A.

My latest effort is the LROW line without the comment - but is this the best
or does anyone know a better or more efficient way?

Function LROW() As Long
' Returns the row number of the last row containing a non-blank entry in a
worksheet
   Application.Volatile
'    LROW = Range("a65536").End(xlUp).Row
   LROW = Application.Caller.Parent.UsedRange.Rows.Count
End Function

--
Brian Pollard
--
Dave Peterson - 18 Jun 2007 01:09 GMT
I think it depends on what you're looking for and how you define last used row.

Ron de Bruin has lots of sample code with different interpretations:
http://www.rondebruin.nl/last.htm

Personally, if I know the data, I like to pick out a column that always has data
in it if that row is used and then use something like:

dim LastRow as long
with worksheets("SomeSheetNameHere")
  lastrow = .cells(.rows.count,"X").end(xlup).row
end with

But you're right.  If you don't know the data, you may not be able to pick out a
column that qualifies.

And because excel remembers the usedrange until you try to reset it, you may not
want to rely on somesheethere.cells.specialcells(xlcelltypelastcell).row.

Debra Dalgleish does share some techniques for resetting that usedrange:
http://contextures.com/xlfaqApp.html#Unused

And depending on what you're doing, you may find that comments and even
formatting are important.  It really makes life easier if you know the data.

> I would like to know the best way of find the row number of the last row
> containg data in a worksheet.
[quoted text clipped - 17 lines]
> Brian Pollard
> --

Signature

Dave Peterson


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.