+ Reply to Thread
Results 1 to 9 of 9

VBA for Last Row

  1. #1
    Forum Contributor
    Join Date
    05-20-2016
    Location
    Detroit
    MS-Off Ver
    Office 365 Version 2008 (July 2020)
    Posts
    819

    VBA for Last Row

    Hi,

    Found this on Internet for last row

    XRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

    Looks like it count OK the last row if there is data in Coulmn A, which is not the case all the time

    How can this be changed if I know that all the time in row there is data in Column 80
    or better
    How can this be changed to look for last row with data in range A7:EZ5000

    Thanks

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA for Last Row

    Try:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: VBA for Last Row

    "...data in Column 80 or better..."

    Not knowing the column, maybe:
    Please Login or Register  to view this content.
    Last edited by protonLeah; 02-17-2022 at 02:22 PM.
    Ben Van Johnson

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA for Last Row

    Bear in mind that UsedRange can be unreliable and can return a higher last row number than actual data rows.

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: VBA for Last Row

    If you don't know which column will have the last value...

    For last value
    ---------------
    LastUsedRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    LastUsedCol = Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column


    For last value or formula
    ------------------------------
    LastUsedRow = Cells.Find("*", , xlFormulas, , xlRows, xlPrevious).Row
    LastUsedCol = Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column


    A note about those headings... the ones labeled "For last value" means it will return the last used row and column for a displayed value (whether a constant or one from a formula) even if there are formulas after those cells displaying the empty string (""); whereas those labeled "For last value or formula" returns the last cell with either a value or a formula even if that formula is displaying the empty string ("").

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: VBA for Last Row

    Take your pick
    Please Login or Register  to view this content.

    Next time I'll use the F5 key Rick to see that you just previously posted!!!!!!!!

  7. #7
    Forum Contributor
    Join Date
    05-20-2016
    Location
    Detroit
    MS-Off Ver
    Office 365 Version 2008 (July 2020)
    Posts
    819

    Re: VBA for Last Row

    Could you please help on this :
    This one work ! XRow = Sheet1.Cells(Rows.Count, 80).End(xlUp).Offset(1, 0).Row
    How can I replace 80 with value from Cell A1 ?

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: VBA for Last Row

    Please Login or Register  to view this content.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA for Last Row

    You're welcome. Thanks for the rep.

+ 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