+ Reply to Thread
Results 1 to 10 of 10

Speeding up my macro

  1. #1
    Registered User
    Join Date
    04-11-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    92

    Speeding up my macro

    Hey Guys!

    Any ideas on how to speed this macro up?

    Please Login or Register  to view this content.

    Also, any tips on how to speed up my macros and excel in General? Thanks!

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Speeding up my macro

    May be this...

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    03-13-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Speeding up my macro

    A standard way to speed up macros is to turn off screen updating. You'll notice the screen flickers as Excel displays each output of the macro, considerably slowing down the start-finish time. To resolve this, start your macro with:
    Application.ScreenUpdating = False
    and end it with
    Application.ScreenUpdating = True

    Hope this helps
    Matt

  4. #4
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Speeding up my macro

    Optimize Slow Code in VBA
    Speed up VBA Code

    Not that it is slowing your code down, but your first Select Case statement is useless as it does nothing, but it still must be read and processed.
    Rather than looping, use AutoFilter and delete all visible rows in one step. It is faster to loop through a short list of filter criteria than every single cell.
    In VBA, it is seldom, if ever, necessary to Activate or Select sheets/ranges/cells, etc. - - just act on them directly
    Please Login or Register  to view this content.
    Example using AutoFilter
    Please Login or Register  to view this content.
    Last edited by Palmetto; 07-02-2013 at 07:34 AM. Reason: slight revision to code
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Speeding up my macro

    perhaps
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  6. #6
    Registered User
    Join Date
    04-11-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Speeding up my macro

    Thanks a lot to everyone!

    Palmetto, how would you implement that on the attached sheet? it seems like checking cell by cell is far too slow...
    Attached Files Attached Files

  7. #7
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Speeding up my macro

    Cell-by-cell checking is exactly what your current code is doing.
    Perhaps I am missing it, but I don't see where you have clearly established your criteria for deleting rows.
    Your code, which doesn't/shouldn't work (because it loops in the wrong direction) just deleting all rows.

    Once you define your criteria for which rows to delete, I (or others) can provide some help.

    how would you implement that on the attached sheet.
    That is what my code example shows. By defning the entire range and filtering it for, say, RF_CORP_TMT, this line of code would delete all rows at once.
    Please Login or Register  to view this content.
    We could then pass another criteria to the filter to continue deleting groups of records, looping only through a short list of criteria and not cell-by-cell.

  8. #8
    Registered User
    Join Date
    04-11-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Speeding up my macro

    Thanks for the help, I have tried to implement it in order two filter out two different criterias, but I get a type mismatch error.

    Could you tell me what I am doing wrong? Thanks
    Attached Files Attached Files

  9. #9
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Speeding up my macro

    Well . . you tried to use my code as is and it was provided only as an example - not the solution since I did not have your workbook when I wrote it.

    You placed the code in the ThisWorkbook module, but it should be placed in a standard module.

    Attached is a working example. I opted to maintain a criteria list on a separate sheet as this approach provides more flexibility for a criteria list than hardcoding a list and using an array. If your criteria list will always be the same, then you might want to use an array of values.

    Included in this version is an option to clear the criteria list on sheet2. Sheet references are to sheet code names, so change them as needed.

    Please Login or Register  to view this content.

    Excel_Forum_DeleteRows.xlsm

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Speeding up my macro

    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)

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