+ Reply to Thread
Results 1 to 5 of 5

Very Slow Macro - Can this be more efficient?

  1. #1
    Registered User
    Join Date
    08-12-2013
    Location
    Wales
    MS-Off Ver
    Excel 2007
    Posts
    7

    Exclamation Very Slow Macro - Can this be more efficient?

    I am trying to write a macro to automatically create a rota.

    I have managed to do it but it is VERY VERY slow, so I need help in making it more efficient.

    The employer plans the rota every quarter, with dates and hours required to be filled - REQUIRED RESOURCE.

    The employees make their availability known each quarter for the rota - AVAILABLE RESOURCE.

    The AVAILABLE RESOURCE is always greater than the REQUIRED RESOURCE.

    The macro I have written goes day by day, shift by shift, allocating the employee with the highest percentage availability to the next shift. It uses a table that is recalculated and reordered every time a shift is filled, and this appears to be the time consuming element.

    I have been advised that there may be a more efficient way of doing this by using VBA within excel, but this is not something I am familiar with.

    The Macro

    Please Login or Register  to view this content.
    Last edited by TonyGill; 09-02-2013 at 09:28 AM. Reason: Use code tags in future.

  2. #2
    Forum Contributor
    Join Date
    05-08-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    102

    Re: Very Slow Macro - Can this be more efficient?

    Here are two things I would recommend.

    [1] Turn the screen updating feature off at the beginning of your code. In particular, include this immediately after your "Sub Rota()" line: Application.ScreenUpdating = False. This will keep your screen from flickering (as Excel is updating the screen for each action that you are taking). Then right before the "End Sub" line, add the following: Application.ScreenUpdating = True.

    [2] When copying and pasting, it is not necessary to apply the .Select method. You do need to select a cell if you are working manually in Excel, but in VBA, you can skip having to select the cells you wish to copy elsewhere. For example, if I want to copy and paste value the contents of Cell A1 into Cell B1, then I could do it as follows:

    Please Login or Register  to view this content.
    Another way to do this, if you do not want VBA to copy and paste, is to simply assign the value in Cell A1 to Cell B1:

    Please Login or Register  to view this content.
    Hope this helps.

  3. #3
    Registered User
    Join Date
    08-12-2013
    Location
    Wales
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Very Slow Macro - Can this be more efficient?

    Thanks Dimitrov

    Done as suggested with regards to the Screen Updating, but it doesn't seem to have improved the performance - it is taking around 10 minutes to populate 160 cells!

    Attached is the whole spreadsheet which hopefully makes the objective a little clearer.

    Is there any way this can be improved to make it quicker, or is there a completely different approach?

    Thanks

    TG
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Very Slow Macro - Can this be more efficient?

    I don't know what the code does but when I ran the macro included in your sample with a few changes it took less than a minute.
    Please Login or Register  to view this content.
    BTW the changes I made were the same as suggested earlier.

  5. #5
    Forum Contributor
    Join Date
    05-08-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    102

    Re: Very Slow Macro - Can this be more efficient?

    Tony,

    Have you had a chance to run John's code. Also, how old is your computer (if I may ask)?

    One other thing I would recommend is to declare your two variables (lr and r) right after the "Sub Rota()" line.

    Please Login or Register  to view this content.
    Not declaring your variables forces VBA to treat your variables as variants. This can be convenient, if you are coding on the fly, but the disadvantage is that your code will probably run slower.
    Last edited by Dimitrov; 09-04-2013 at 04:11 PM.

+ 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] slow computer (slow clipboard) breaks my macro
    By twilsonco in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2013, 09:16 PM
  2. [SOLVED] Very slow macro
    By ESF in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-05-2012, 05:17 AM
  3. Macro Very Slow
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-07-2010, 06:15 PM
  4. How to slow down a little a macro
    By feejo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-11-2007, 02:38 AM
  5. Slow macro
    By AG in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-24-2005, 09: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