+ Reply to Thread
Results 1 to 6 of 6

Speedier Alternative To Existing Code

  1. #1
    Valued Forum Contributor
    Join Date
    09-23-2005
    Location
    Bristol, UK
    MS-Off Ver
    2007
    Posts
    664

    Speedier Alternative To Existing Code

    Hi all,

    I found a bit of code while trawling Google that deletes a row if it finds a specified value in a specified column (in this instance, "NB" in column E). However, it is very slow and some end users are complaining about the amount of time it takes to run. I was wondering if anyone can suggest an alternative that might be a bit faster. Here's what I'm using at the moment:

    Please Login or Register  to view this content.
    TIA,

    SamuelT
    Last edited by SamuelT; 12-24-2009 at 06:57 AM.

  2. #2
    Registered User
    Join Date
    11-20-2009
    Location
    Raymond,WA
    MS-Off Ver
    Excel 2002
    Posts
    40

    Re: Speedier Alternative To Existing Code

    Have you tried turning screen-updating off?

    Also, it is said that one should always start at the bottom and work your way up when one is deleting rows. Less stuff gets moved.
    Last edited by TimK; 12-23-2009 at 01:56 PM. Reason: added comment

  3. #3
    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: Speedier Alternative To Existing Code

    Hello SamuelT,

    There are a few tricks to speed up the process. First, use a block move to copy the cell values into an array. It is much quicker to access the array elements than the cells themselves. The next trick is create an array of rows themselves using the Union method for a Range object. We can then have the system delete our data without creating a For...Next loop. Here is the revised macro. It uses the methods I just described.
    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!)

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Speedier Alternative To Existing Code

    If the data is in a table like structure you could use AutoFilter to filter for NB then delete the results. You can record the basic code for this
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Valued Forum Contributor
    Join Date
    09-23-2005
    Location
    Bristol, UK
    MS-Off Ver
    2007
    Posts
    664

    Re: Speedier Alternative To Existing Code

    Thanks guys - I will have a look at all the suggested methods.

    Merry Christmas!

    SamuelT

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Speedier Alternative To Existing Code

    be sure to post back and let us know how it works out

+ 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