+ Reply to Thread
Results 1 to 7 of 7

Delete Empty Rows of Table And Optimize Code

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

    Delete Empty Rows of Table And Optimize Code

    I have four worksheets (see sample). The goal is to copy Col A from the first three worksheets to Col A of the fourth worksheet, sort the result and get rid of empty rows. Here is what I have done so far in the code below:

    Delete old data from Col A of table on Worksheet 4
    Copy Col A of Worksheet 1 to Col A of Worksheet 4
    Copy Col A of Worksheet 2 to Col A of Worksheet 4
    Copy Col A of Worksheet 3 to Col A of Worksheet 4
    Sort Col A of Worksheet 4 to separate data from empty cells

    Please Login or Register  to view this content.
    My original idea was to copy the data into an array or variable, sort the data to exclude the empty cells and then paste the data into Worksheet 4 but I am sorely lacking in the proper skills.

    Would you kindly look this over and suggest a better way?

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Delete Empty Rows of Table And Optimize Code

    Hi snapfade,

    Here's a proposal. Copy the data to a temp sheet, sort in this temp sheet and then copy the sorted rows in your destination sheet.
    Finally, sort the table in the destination sheet (no empty rows to consider)

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Delete Empty Rows of Table And Optimize Code

    If you want to delete the old data in sheet 4, this alternative will work as well:

    Please Login or Register  to view this content.
    Last edited by berlan; 12-14-2013 at 12:18 AM. Reason: typo

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

    Re: Delete Empty Rows of Table And Optimize Code

    Please Login or Register  to view this content.
    Ben Van Johnson

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

    Re: Delete Empty Rows of Table And Optimize Code

    Hi GC Excel, berlan and protonLeah,

    A hardy THANKS to all three of you for your thoughtful help. I am learning so much I'm gonna be dangerous one day! I have loaded, studied and tried all three solutions. All three do the job for the most part. I will now work with some elements of all three and post my solution for the benefit of all members. In the meantime here is what I found:

    GC Excel's post expanded nicely on my effort by doing away with the individual variables and using For-Next to cycle through. The use of an extra worksheet works fine. This procedure needs the addition of code to erase sheet Four before pasting. Easy to fix.

    berlan also shortened my procedure nicely, but went way beyond my meager approach by doing the entire copy/paste in just a few lines of code. Very impressive...but then, I am easily impressed. ;-) This code worked perfectly.

    protonLeah came up with the solution I think I was looking for by using an array. This code will take a lot more study on my part to understand what is happening but I am guessing that if we clock it, it might be the fastest, which is great because the real workbook has thousands of rows in each sheet. This solution deleted the entire results table along with its formulas but that even I can fix.

    My comments may seem like the teacher lecturing students...nothing could be farther from the truth. I have learned so much from the three of you that I will be documenting my discoveries all day!

    As I said, I will now attempt to cobble together all the great work into one solution and post it here for all.

    Thanks again for the generous gift of your time and energy. I really appreciate it.

  6. #6
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Delete Empty Rows of Table And Optimize Code

    Thanks for the feedback, very much appreciated

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

    Re: Delete Empty Rows of Table And Optimize Code

    Hi protonLeah,

    I attempted to modify your code to delete only the rows of Sheet Four from Row 3 down but my "fix" caused an error with the last line of code, which I also modified. I fear I have made matters worse. I also need to sort the result.

    Help, please! And thank you.

    Please Login or Register  to view this content.

+ 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. Code Amendment - Delete Empty Rows
    By TextMonkey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2013, 08:03 AM
  2. [SOLVED] still have empty cell after run Delete empty cells code
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-25-2012, 04:28 PM
  3. Autofilter/delete empty rows is deleting non-empty rows!
    By oOarthurOo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-05-2010, 12:31 PM
  4. Optimize delete dupe rows
    By Engineers2008 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2010, 04:54 PM
  5. Code to Delete Empty Rows in a Word Table
    By Araknia777 via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-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