+ Reply to Thread
Results 1 to 9 of 9

Code execution is extremly slow

  1. #1
    Registered User
    Join Date
    09-30-2014
    Location
    Luanda, Angola
    MS-Off Ver
    windows 7
    Posts
    3

    Code execution is extremly slow

    Hi,
    Can someone help me with this code?
    Everthing is working fine but the execution is too slow.
    There is anyway to improve it?
    Thanks in advance.

    http://www.mrexcel.com/forum/excel-q...ml#post4695665

    Please Login or Register  to view this content.
    Last edited by frog10; 11-30-2016 at 02:38 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Code execution is extremly slow

    Your running a loop inside a loop, how many times does the code loop?

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Code execution is extremly slow

    Not knowing what is in your spreadsheet, I can only suggest that you turn off Auto Calculations and add lines of code to Turn off Screen Updating. Each of these will help to speed up the action of your double looping macro.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    09-30-2014
    Location
    Luanda, Angola
    MS-Off Ver
    windows 7
    Posts
    3

    Re: Code execution is extremly slow

    3000 rows.
    I can't turn off auto calculations beacuse the code needs to caclulate in each of the rows

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Code execution is extremly slow

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    crosspost: http://www.mrexcel.com/forum/excel-q...ml#post4695665

  6. #6
    Registered User
    Join Date
    09-30-2014
    Location
    Luanda, Angola
    MS-Off Ver
    windows 7
    Posts
    3

    Re: Code execution is extremly slow

    I'm sorry, was the first time that I posted a question, i was not sure about the rules.

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Code execution is extremly slow

    Turn on Calculations after code has been completed. This will speed up your code. With 3000 lines and recalculation on every line, your code will definitely be slowed down.

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Code execution is extremly slow

    Currently your code is testing the values of several cells against a number of "IF" statements.
    It loops through all your rows.
    I would expect the time to reduce if the data is filtered PRIOR to running the code,for 2 reasons:
    - fewer rows to loop through
    - fewer "IF" statements to test against

    "IF" statements are just another way of filtering the data.But Data Filter is much quicker.

    If Worksheets("Inputs Pendentes").Cells(RowPendentes, 33).Value = ""
    is the same as Data Filter in column 33 with value = ""

    If Worksheets("Inputs Pendentes").Cells(RowPendentes, 31).Value = "Não"
    is the same as Data Filter in column 31 with value = "Não"

    If Worksheets("Input Regras").Cells(RowRegra, 10).Value < Worksheets("Input Regras").Cells(RowRegra, 9).Value
    Add a "helper" column to the sheet "Input Regras" with formula =IF(I16>J16,"XX","") in cell J16 and copied down
    Then filter in that column for values "XX"


    So, you could try the following
    1 Add the "helper" column in sheet "Input Regras", apply Data Filter as suggested above
    2 Copy the filtered sheet and paste it to a new sheet (only the filtered values will be pasted)
    3 Delete sheet "Input Regras" and then rename your new sheet "Input Regras"
    4 Filter sheet "Inputs Pendentes" as suggested above
    5 Copy the filtered sheet and paste it to a new sheet (only the filtered values will be pasted)
    6 Delete sheet Inputs Pendentes" and then rename your new sheet "Input Regras"
    7 Amend the code to remove the 3 if statements that are no longer required.

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Code execution is extremly slow

    Here is a simplified example (with all the data in a single sheet) to illustrate comments in post#8 above
    These 2 macros yield the same results, one by data filter, one by IF statements
    Workbook containing macros is attached

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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] macros in excel 2007 extremly slow
    By mandura in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2016, 06:50 AM
  2. significant code execution slow down when excel is in background
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2015, 12:58 AM
  3. Macro is running real slow and makes navigating the worksheet really slow after execution.
    By MichWolverines in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2013, 04:29 PM
  4. [SOLVED] Slow Macro Execution
    By Gandalf2524 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-18-2013, 12:20 PM
  5. Slow VBA execution
    By GustavBA in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2013, 06:40 AM
  6. Excel extremly slow when formatting cells
    By alexdeangelis in forum Excel General
    Replies: 0
    Last Post: 08-12-2008, 01:24 AM
  7. Slow code execution
    By side_ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-21-2005, 01:44 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