+ Reply to Thread
Results 1 to 2 of 2

LastRow issue

  1. #1
    Registered User
    Join Date
    02-13-2013
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    11

    LastRow issue

    I'm new to VBA and stuck on an issue defining the "last row". I defined the last row as the following: LastRow = Cells(Row.Count,1).End(xlUp).Row. I reference this variable multiple times in the same Sub across different worksheets but it only works the first time on the first worksheet. I've found that redefining the LastRow before the second reference works but I'm wondering how I could change the code such that I don't need to define it twice in the same Sub.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: LastRow issue

    The method you are using to find the last row relies on the length of column A. Another way to define the last row, regardless of which column is the longes is:
    Please Login or Register  to view this content.
    The lstRw variable will have to be re-initialized if you add or delete rows or clear contents of the original last row, any of which would then physically change which row has the last vertical data entry. The variable is not dynamic and will not change automatically when you change the sheet content. You can find several articles on 'last row variable' by web search which go into greater detail about using a varible to definge the row you want to use.
    Last edited by JLGWhiz; 12-22-2019 at 02:08 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Autofill Data based off current sheet lastrow not first sheet lastrow
    By bcarroll76 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-06-2018, 06:26 PM
  2. VBA Not Printing to LastRow
    By slantz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-06-2016, 09:53 AM
  3. R1C1 lastRow not lastRow when data combined
    By Spyderwoman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2016, 05:20 PM
  4. [SOLVED] LastRow - for next loops longer than lastrow?
    By flabb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-07-2016, 12:39 PM
  5. [SOLVED] VBA Using LastRow AND LastColumn Together
    By phelbin in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-11-2015, 05:22 PM
  6. Copy From LastRow to LastRow+7
    By dvent in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2010, 06:56 AM
  7. LastRow function - #VALUE
    By slc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-01-2005, 05:05 PM

Tags for this Thread

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