+ Reply to Thread
Results 1 to 9 of 9

Speeding Up Macro

  1. #1
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Speeding Up Macro

    I have the below which deletes any row that does NOT contain the string "TypeA Disease|English Irish American Matches|". Is there any way to speed the below up as it takes about 2 minutes to run.
    Please Login or Register  to view this content.
    Last edited by ScabbyDog; 01-03-2015 at 09:19 AM.

  2. #2
    Registered User
    Join Date
    05-13-2014
    Location
    Best
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Speeding Up Macro

    try this:
    Set Rng = Range("C1:C" & Cells(Rows.Count, 3).End(xlUp).Row)

    This minimizes the RANGE to Search and hence increase the speed proportionally to the size of the array.

    success

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Speeding Up Macro

    Hi,

    Always avoid VBA loops wherever possible. They are just too slow when compared to standard Excel functionality
    The fastest way I know of doing this sort of stuff is to use Autofilter to show the rows you want to delete then just select and delete them in one hit.

    Use a helper column (say column D) to identify the rows, e.g.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then
    Please Login or Register  to view this content.
    ' change the 10000 as necessary
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Speeding Up Macro

    Getting a 'delete method of range class failed' for the very last line of code Richard. I think it's because it can't execute the code while a filter is applied? Maybe I am wrong.

    Please Login or Register  to view this content.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Speeding Up Macro

    No, deleting filtered rows is a quite normal practice, and indeed the code worked for me when I tested it.

    Have you perhaps got sheet protection on.

    If not upload the workbook so that we can see what might be the problem.

  6. #6
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Speeding Up Macro

    Attached....in next post...
    Attached Files Attached Files
    Last edited by ScabbyDog; 01-03-2015 at 10:50 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Speeding Up Macro

    sampelbook (1).xlsm

    use this one. Thanks!

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Speeding Up Macro

    Hi,

    Seemingly Excel Tables don't like the syntax. Personally I rarely use the Table functionality preferring to use normal ranges. I find it just complicates things when you need to reference cells in the table from outside it.

    You could either convert your Table to a Range and use the code I gave you or change the code syntax to

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Speeding Up Macro

    Brilliant Richard. Hero.

+ 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. [SOLVED] Speeding up my macro
    By jsuarez199 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-03-2013, 10:52 AM
  2. [SOLVED] Help in speeding up my macro!
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2013, 12:04 PM
  3. [SOLVED] Speeding up a macro process
    By pezalmendra in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-07-2012, 03:32 PM
  4. Speeding up a macro
    By Mister P in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 12-20-2010, 02:50 AM
  5. Help with speeding up vlookup macro
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-20-2006, 01:05 PM

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