+ Reply to Thread
Results 1 to 11 of 11

Worksheet Calculate Event slows down workbook

  1. #1
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Worksheet Calculate Event slows down workbook

    Greetings,

    I have the following worksheet code for displaying a hidden object if there are any formula errors.

    If I run any macro (or show a userform) in the workbook, the screen flickers slightly (even though screenupdating is turned off) and the workbook slows down. Using the calculation timers from MS support, I found that the full workbook calculate time was 0.20 secs. If I eliminated the below code, the full workbook calculate time was 0.09 secs. Also, I did not see the screen flicker.

    Is this normal when using the workbook calculate event? Any guidance would be appreciated.

    Many thanks
    Asha

    Please Login or Register  to view this content.
    Last edited by asha3010; 11-10-2010 at 07:57 AM.

  2. #2
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Dorset, UK
    MS-Off Ver
    Office 2003, Office 2007
    Posts
    131

    Re: Worksheet Calculate Event slows down workbook

    It's not surprising that adding the code causes the calculate time to increase, as the code takes a small but finite time to run.

    Also, it is likely that the screen flickers not because you turn ScreenUpdating off but because you turn it back on again. Obviously this is a necessary step, however when you turn it back on the screen needs to update in case soemthing has changed and so you see the flicker

    Is it possible for you to leave screen updating on unless you are changing something? For example if the shape is visible and is going to stay visible then don't turn screen updating off and on. For that matter, do you need to turn screen updating off at all, since you are only making the one visual change and not running a lot of other code?

  3. #3
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Worksheet Calculate Event slows down workbook

    Hi Kafrin,

    Thanks for your prompt and detailed response, which was spot-on in identifying the problem.

    Based on your response, I was trying to understand what caused the worksheet calculate event to be triggered when the macro / userform was run in a different sheet and the resultant data had no connection (precedents or dependents) with the worksheet containing the calculate event.

    What I concluded (hopefully correct!) is that since my workbook was in autocalucation mode, clearing existing data / adding new data (which is what the macro / userform did) triggered full recalculation which turned on the screenupdating & hence caused the flickering.

    After removing the code for screenupdating, the screen no longer flickers.

    Thanks again for your time
    Asha


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

    Re: Worksheet Calculate Event slows down workbook

    Why so complicated ?

    Please Login or Register  to view this content.



  5. #5
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Worksheet Calculate Event slows down workbook

    Thanks for your reply.

    The intent is to display a textbox (by default hidden) that lists the possible causes of cell errors & its resolution. Also did not want a message box that would lock the application.

    Not sure how to capture the above in a more concise manner! Am open to any improvements in the code.

    Regards
    Asha


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

    Re: Worksheet Calculate Event slows down workbook

    A msgbox doesn't block an application, it only delays execution until the user clicks on a button.

    Please Login or Register  to view this content.
    This shows the popup for 3 seconds.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Worksheet Calculate Event slows down workbook

    I'd just add that in my experience the Popup method is unreliable in terms of dismissing itself.
    Everyone who confuses correlation and causation ends up dead.

  8. #8
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Worksheet Calculate Event slows down workbook

    Thanks for your replies romperstomper, snb.

    A msgbox doesn't block an application, it only delays execution until the user clicks on a button.
    In my model that can be a problem because I need to do a few things (for eg navigate between sheets to update data) which cannot be done until I click a button on the message box or close it. And then, I cannot see the contents of the message box.

    Regards
    Asha

  9. #9
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Dorset, UK
    MS-Off Ver
    Office 2003, Office 2007
    Posts
    131

    Re: Worksheet Calculate Event slows down workbook

    Quote Originally Posted by asha3010 View Post
    What I concluded (hopefully correct!) is that since my workbook was in autocalucation mode, clearing existing data / adding new data (which is what the macro / userform did) triggered full recalculation which turned on the screenupdating & hence caused the flickering.
    I think your conclusion is correct, and I'm glad I could help.

    One thought:
    If the code only applies to one sheet, how about starting with "If ActiveSheet.Name="Sheet27" Then ..."

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

    Re: Worksheet Calculate Event slows down workbook

    In VBA it isn't necessary to 'navigate between sheets' to update data.
    Besides you can show msgbox/popup whenever you want:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Worksheet Calculate Event slows down workbook

    Thanks to both for your replies. I will see how to incorporate this into my current code.

    @ snb: When I mentioned navigation between sheets - it was not via VBA. To clarify - one of the functions of my worksheet is to compute the total cost of a trading transaction and compare it with the invoice downloaded from the service provider site. There could be a difference and hence an error if I have not updated the latest trading fees in the workbook. So, I have to go to the worksheet containing the fees & update it.

    Regards
    Asha

+ 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