+ Reply to Thread
Results 1 to 4 of 4

Loop for Deleting Rows

  1. #1
    Registered User
    Join Date
    04-07-2009
    Location
    Isarel
    MS-Off Ver
    Excel 2003
    Posts
    13

    Loop for Deleting Rows

    Hello Experts

    Whats wrong with my code ?
    Please Login or Register  to view this content.
    Thanks
    Sharky
    Last edited by Sharky Amit; 04-20-2009 at 05:36 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Loop for Deleting Rows

    When you delete rows you should work in reverse - bottom up...

    If you consider you have rows 2:10 and you loop from 2 to 10, when you delete row 3 then what was row 4 is now 3 yet you miss it as you go to 4 (which was 5), make sense ?

    Better then to adopt something along the lines of:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Loop for Deleting Rows

    Exactly right...and if you're deleting a LOT of rows, then the code will execute much faster if you turn off the screenupdating:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Loop for Deleting Rows

    If speed were a concern then I would make the point that as much as ScreenUpdating will slow code, given Deletion of Rows is a Volatile action if you have Volatile functions you're best served forcing Calculation to Manual prior to implementation of Deletion Loop and restoring Calc to it's former setting on completion ... and if you do that you may as well do all three, ie: screenupdate, calculation & events.

    An example below:

    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)

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