+ Reply to Thread
Results 1 to 9 of 9

Execution Speed of VBA Code

  1. #1
    Registered User
    Join Date
    07-13-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    11

    Execution Speed of VBA Code

    Good Day

    I have a question regarding being able to improve the speed of the following code:

    Please Login or Register  to view this content.
    Is there a way to accelerate the execution by rewriting it somehow?

    Thanks in advance!

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Execution Speed of VBA Code

    How long could that code possibly take? There doesn't seem to be much going on there!
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    07-13-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Execution Speed of VBA Code

    It takes about 5 to 10 seconds to execute the collapse. There is approximately 100 groupings that need to be expanded or collapsed when the code is triggered. The expansion runs 3 to 4 times faster than the collapse.
    Last edited by Cutter; 07-17-2012 at 08:35 PM. Reason: Removed whole post quote

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Execution Speed of VBA Code

    Hello sdelaney7,

    If you are having speed issues with your code then there is probably more going than this Sub. There really isn't anything you can do to achieve a significant speed improvement with this Sub. VBA can not speed up the process of expanding and collapsing the rows. Unprotecting and protecting the worksheet takes no time at all. I would suggest you post a copy of the workbook for review and then we can offer more practical advice.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    07-13-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Execution Speed of VBA Code

    I have attached a redacted version of the file for your review. Thanks for the response!
    Attached Files Attached Files
    Last edited by Cutter; 07-17-2012 at 09:07 PM. Reason: Removed whole post quote

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Execution Speed of VBA Code

    Hello sdelaney7,

    That's insane! It took about 15 seconds to collapse on my machine. The only thing I can suggest is to reduce the number of groups you are collapsing, if possible. Doing smaller chucks will be faster. Since this function is built-in, there is no other way to gain speed improvement.

  7. #7
    Registered User
    Join Date
    07-13-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Execution Speed of VBA Code

    My sentiments exactly (but your response used no expletives and my thoughts contained many). I'd like to pick your brain on this some more though if you don't mind. If sheet calculations are set to manual, the process of expanding and collapsing groups is almost instantaneous. Is there a way to code for the calculations to be set to manual upon execution and then revert to automatic once complete? This would be an acceptable workaround given the way the users interface with the workbook.
    Last edited by Cutter; 07-17-2012 at 09:08 PM. Reason: Removed whole post quote

  8. #8
    Registered User
    Join Date
    07-13-2012
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Execution Speed of VBA Code

    I solved the problem by manipulating whether or not automatic calculations were enabled in the code.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Execution Speed of VBA Code

    Hello sdelaney7,

    That's interesting. I did not look for any formulas that were being calculated which of course would slow things down. Thanks for pointing that out. Glad you got it solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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