+ Reply to Thread
Results 1 to 24 of 24

Finding Last Row of Data in a Table

  1. #1
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Finding Last Row of Data in a Table

    My table has 182 rows and formulas in many columns but Column A is the key. It has data down to only row 18. I want to delete all rows of the table beneath the last row where column A has data. That is, I want to delete table rows 19 through 182.

    When I use the...

    Please Login or Register  to view this content.
    it yields 182, not 18. How can I modify this code to get the right answer?

    Thanks!

  2. #2
    Registered User
    Join Date
    08-11-2013
    Location
    leeds
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Finding Last Row of Data in a Table

    lastrow = thisworkbook.sheets(1).cells(rows.count,"a").end(xlup).row

  3. #3
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    Thanks for the quick reply, notreallyIT, but this code yields 182 as does my original code.

    I think the challenge here is that I am using the newish Tables feature (really quite awesome). Tables are ListObjects and I suspect special coding may be needed.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding Last Row of Data in a Table

    Please Login or Register  to view this content.
    will find the last row in table.
    How is your goggling going on? Any magic short cut yet?

  5. #5
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    Hi again AB33.

    Your code yields 182, just like the other examples. There are 182 rows in the table and all columns other than A have formulas. But Column A only has data down to row 18 so I want to delete rows below that.

    I have quit tilting at windmills for the time being. ;-(

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Finding Last Row of Data in a Table

    Hello snapfade,

    This macro will clear the cells in column "A" that contain formula errors or are empty either because there is no data or as th result of a formula. It is setup for "Sheet1". Change this to match the sheet you are using.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    Hi Leith,

    am getting a type mismatch on...

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    Leith, I should have asked what that line does. Also, I think I may want to delete the rows rather than clear contents.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Finding Last Row of Data in a Table

    Hello Snapfade,

    Try This out. LastRow has to be a Variant because match can return either a number or error.
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding Last Row of Data in a Table

    Try

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    Leith, now getting the type mismatch on the next line...

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    AB33...progress. Selected the last row of data. Now, how do we delete the rest of the records in the table?

    BTW, where is TBD? I asked Carmen San Diego and she was clueless. ;-)

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding Last Row of Data in a Table

    To be Decided!
    I am stateless

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding Last Row of Data in a Table

    Untested

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    Ouch! that deleted column A. And I just learned that there is no undo. no problem...have a version from yesterday.

  16. #16
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding Last Row of Data in a Table

    snapfade,
    This is a learning process. As a good practice, you should always save your data before you run a code.
    I was not sure sure if it is going to work.

  17. #17
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    Not a problem, AB33. This isn't my first rodeo. When working on a project like this I save a new copy at the start of every day and sometimes throughout the day. THAT I learned long ago and far far away in a place near TBA.

    Any suggestions on fixing that code?

  18. #18
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    Attached is a sample table. Col A is rows 2-13. Rows to be deleted are 14-29
    Attached Files Attached Files

  19. #19
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding Last Row of Data in a Table

    Well, I now have tested it and seems to copy the desired range. I have chosen copy rather than delete.
    Try it.

    Please Login or Register  to view this content.

  20. #20
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding Last Row of Data in a Table

    Delete A-G
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    Wonderful! Works perfectly. Thanks for all your help, AB33. Hope you find a state soon. tom

  22. #22
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding Last Row of Data in a Table

    Two more clarification.

    1. To be Announced( Not decided)
    2.When I said save, I was not referring to the usual save. This is how I normally work with macros: Copy the code in the module first then before I run it , I save my file. If the code is wrong, I can go back to the pre-run stage. This preserves my original data and the code is still on the module.
    You probably did not get the message. I asked you how is your search for ideal VBA course going on.

  23. #23
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Finding Last Row of Data in a Table

    1. good luck
    2. understood
    3. I did reply -- that I am done tilting at windmills for now. Still interested but less enthusiastic about finding a course. Hoping to find a good reference. It just drives me nuts that there are so many ways to get a line of code wrong...and so few ways to get it right. Clearly, it is trial and error because if it made more sense it would be called trial and success. I am thankful for this forum; it has been enormously helpful in my work and by the time i have 7000 posts I too may have a clue. ;-)

    Thanks again!
    Merry Christmas
    tom

  24. #24
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding Last Row of Data in a Table

    Given your back ground in programming, I am sure you do not need to reach the 7 figure.
    Once you start kicking-in through trial and error, all your previous knowledge will come in handy to help trim the 7 figure.

+ 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. Finding data in a Table
    By goony in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-11-2012, 07:51 AM
  2. finding specific data from one table and pasting it into another table
    By saranorton in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-29-2011, 09:35 AM
  3. finding data in one table and copying to another.
    By corkyo4 in forum Excel General
    Replies: 4
    Last Post: 04-16-2010, 05:54 AM
  4. Excel 2007 : Finding a Data Table
    By heski in forum Excel General
    Replies: 2
    Last Post: 08-13-2008, 10:43 AM
  5. Finding the 2nd to last data in table
    By scottymelloty in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-21-2008, 11:26 AM

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