+ Reply to Thread
Results 1 to 20 of 20

Macro runs Slowly

  1. #1
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Macro runs Slowly

    Hi Guys,



    The macro below works perfectly fine. It creates 250 rows in Sheet 1 and copies formula . Then it does the similar

    thing in Sheet 2. However this macro runs slowly. Can any one speed it up?

    Thanks

    Please Login or Register  to view this content.
    Last edited by ConneXionLost; 02-05-2012 at 11:59 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro runs Slowly

    Hi

    Not sure what you have in your formulas, but see how this goes.
    Please Login or Register  to view this content.
    rylo

  3. #3
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro runs Slowly

    Hi Rylo,

    Tried your code but debugs at Sheets (Shtarr(i)).Activate (6th Line)
    I see your code is assuming that both sheets are identical which is not the case. Any help here?

  4. #4
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Macro runs Slowly

    You appear to have commented out the line that turns off screenupdating. I suggest you uncomment that line and also set calculation to manual at the start and back to automatic at the end. Furthermore all that selecting is unnecessary - you can just manipulate the ranges directly.
    Good luck.

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro runs Slowly

    Hi

    1) check the sheet names. I just took them from your code, but if it isn't right, then it will error.

    2) Missed that difference. You could just duplicate the code and specifically nominate the sheet as you have done, as I think the insertion method will still be faster.

    Better still, put up an example file for review. Makes things much easier to work through.

    rylo

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: Macro runs Slowly

    Not tested, but this should be very quick...
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro runs Slowly

    Hi Dangleor

    Thanks for your input but the code you are suggesting are only inserting rows and does not copy forumuals.
    Please refer to my original code, the macro is inserting and copying formulas only. This it does to both my sheets.
    The macro is absolutely fine but i need a code to speed it up.
    Thanks

  8. #8
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro runs Slowly

    Mysore

    really think we need the example file to work with here....

    rylo

  9. #9
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro runs Slowly

    Hi Guys,

    Just Attaching a sample worksheet. I have just revised the macro to loop 2o times for
    illustration purpose but the final version will have 250 rows to add and copy formulas.


    Hope this helps

    Thanks
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro runs Slowly

    Hi

    I've just tweaked dangelor's code a bit and I think it gives you what you are chasing.

    Please Login or Register  to view this content.
    rylo

  11. #11
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro runs Slowly

    Hi Rylo

    Thanks for the code. Is is certainly faster. Just one hurdle to cross. The Data Input - Sheet is fully protected but permits
    data entry only in specific range. The new rows which are created are locked. My earlier macro did have not this issue.
    Maybe when the formula copies, it should copy the formats as well and this could help,
    Can you tweak the code?

    Thanks

  12. #12
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro runs Slowly

    Hi

    Give some examples of the ranges so we know exactly what / where to check.

    rylo

  13. #13
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro runs Slowly

    Hi rylo

    Range A8 - DW308 in the Data Input - Unit Leader Sheet in my original file. Infact you look at my attachment and run the macro.
    This might give u an understadning

  14. #14
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: Macro runs Slowly

    Try...
    Please Login or Register  to view this content.

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

    Post Re: Macro runs Slowly

    refrain from 'activate'

    Did you consider to use:

    Please Login or Register  to view this content.



  16. #16
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Macro runs Slowly

    @snb,
    Usedrange needs a sheet.

  17. #17
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro runs Slowly

    Hi Dangelor,

    I used the above code but it groups the newly inserted rows since the row where it copies the formula is grouped.
    This cannot be ungrouped by the user as the worksheet is protected.
    Please refer to the original file I have attached and the macro does not group the new insertion .

    Appreciate if you can tweak it.

    Thanks

  18. #18
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Macro runs Slowly

    Hi Rylo,

    Did you get a chance to have a look at it?

  19. #19
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro runs Slowly

    Hi

    You will have to change the row that you are copying (on the first sheet row 311 in the example file) to have to correct cell permissions. Otherwise, you will have to change the row that you want to use as the base row to copy. Given you have drop downs as well, it may pay to put those into the main copy row as well.

    rylo

  20. #20
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: Macro runs Slowly

    Tweaked...
    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