+ Reply to Thread
Results 1 to 4 of 4

Faster way of deleting rows in macro?

  1. #1
    Registered User
    Join Date
    05-15-2020
    Location
    Portland, OR
    MS-Off Ver
    Office 365 ProPlus
    Posts
    4

    Faster way of deleting rows in macro?

    I am wondering if there is a faster way to delete selected rows in a macro. I recorded this short macro using data filter to select all rows with nothing in the first column, then deletes them all.

    Cells.Select
    Application.CutCopyMode = False
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$T$3295").AutoFilter Field:=1, Criteria1:="<>"
    Rows("2:65536").Select
    Selection.Delete Shift:=xlUp

    When recording the macro each step works instantly. When running the macro, it works correctly but it takes 30 seconds to run. I suspect that the macro may be slow because of the line: “Rows("2:65536").Select” which runs the macro on all 65536 possible rows. The number of rows in the spreadsheet can vary. In this case the spreadsheet had about 4000 lines.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    5,124

    Arrow Re: Faster way of deleting rows in macro?


    You must edit your post and use code tags (easy with the icon) …

    Cells.Select is for all cells in the 16 384 columns x 1 048 576 rows so a lot, not a great idea !
    Of course with an explanation and an attachment, both smart enough, further help should follow …

  3. #3
    Registered User
    Join Date
    05-15-2020
    Location
    Portland, OR
    MS-Off Ver
    Office 365 ProPlus
    Posts
    4

    Re: Faster way of deleting rows in macro?

    I have found this code to work MUCH faster:

    Please Login or Register  to view this content.
    Last edited by LonnieC; 05-19-2020 at 08:02 AM. Reason: Adding code tags

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,627

    Re: Faster way of deleting rows in macro?

    @ LonnieC

    Administrative Note:

    Welcome to the forum.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ 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. Macro for deleting all rows, except first one and last one of every day
    By Bender000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-04-2017, 02:32 PM
  2. [SOLVED] Macro help with combining data across 2 rows (and deleting non-required rows)
    By InnesMcc in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 05-20-2013, 05:21 AM
  3. [SOLVED] Deleting rows in more faster way
    By thisisgerald in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-03-2012, 06:35 AM
  4. Excel 2007 : Deleting Rows Macro
    By Mike74 in forum Excel General
    Replies: 2
    Last Post: 06-23-2010, 03:25 PM
  5. How to make my macro delete rows? It currently hides the rows instead of deleting.
    By Majkataxmk in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-20-2010, 01:14 PM
  6. macro for deleting rows
    By janjan_376 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-23-2009, 09:14 PM
  7. Deleting rows with macro
    By Elise.B in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-19-2009, 06:10 AM

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