+ Reply to Thread
Results 1 to 4 of 4

Excel help to find last row

  1. #1
    Registered User
    Join Date
    04-02-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    16

    Excel help to find last row

    Hi All,

    I need to find the last row in an excel sheet. I have a worksheet with many sheets in it.

    When i try to get the value of last row using the following formula, even after specifying the sheet as sheet21 , it is returning the last row in the main sheet that is sheet1.

    Any thing I am missing ?

    LastRow = Sheet21.UsedRange.Rows.Count

    Please let me know.

    Thanks
    Saran

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Excel help to find last row

    Try this approach instead...UsedRange is notorious for giving false answers even if you do get the macro to read the correct sheet. In this sample, I'm spotting the "last row" based on column B. Change that to the column you KNOW will always have a value in the last row.

    Please Login or Register  to view this content.
    Use the actual sheet name in place of "Week 5".
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-28-2009
    Location
    Rochester, New York, USA
    MS-Off Ver
    Office 2003 (work), Office 2007 (home)
    Posts
    8

    Re: Excel help to find last row

    The traditional "trick" to grab the last row is with the MATCH function...

    Please Login or Register  to view this content.
    where "9E308" is a value much, much bigger than anything you've got in the column, and a:a is the column you're looking in.

    I'm a big fan of avoiding macros and VBA when there's a simplier solution... of course, if this is a single error in a larger project, this might not be very helpful.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Excel help to find last row

    Quote Originally Posted by dg
    =MATCH(9E308, a:a)
    You can't use 9E308 in a formula, daniel; the largest value is a tad less than 1E308 (i.e., 9.99999999999999E+307)
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1