Results 1 to 14 of 14
  1. #1
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Louisville, Kentucky, USA
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Timing a Calculation (97 SR-2)

    In a previous thread I started about the benefits of declaring your VBA variables, one of the stated benefits is faster execution time. While I believe this to be true, I would like to run a little test to see how much speed can be gained by proper declaration of variables.

    I have been working with a spreadsheet where I have a user-defined function that is entered in thousands of cells. As needed, I hit ctrl-alt-f9 to force a total recalc and the whole thing takes about 15 minutes. I know how to time the execution of a Sub by capturing the value of NOW at the beginning and end of the Sub, but is there a way to time a ctrl-alt-f9?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Timing a Calculation (97 SR-2)

    I'm not entirely sure about this, others will correct me if I'm wrong. I think that Application.CalculateFull is the VBA equivalent of Ctrl+Alt+F9. So you could create a procedure that stores the time, executes the above instruction and then checks the time again.

    Note: I use the Timer function to measure execution time. It returns a value of type Single that represents the number of seconds since midnight.

    Dim sngTime As Single
    sngTime = Timer
    Application.CalculateFull
    sngTime = Timer - sngTime
    MsgBox "Execution took " & Format(sngTime, "0.00") & " seconds"

  3. #3
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Louisville, Kentucky, USA
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Timing a Calculation (97 SR-2)

    Hans,
    My VBA doesn't seem to recognize calculatefull. I've previously looked for a VBA equivalent to ctrl-alt-f9, but I've never found one.

    The TIMER function is cleaner than using NOW. However, it seems TIMER won't work if the execution of your code is executing at midnight. <img src=/S/doze.gif border=0 alt=doze width=15 height=15>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Timing a Calculation (97 SR-2)

    I'm using Excel 2002. CalculateFullRebuild is listed as a new method in the online help, but CalculateFull isn't. Perhaps it was introduced in XL 2000?

    You could take midnight into account when using Timer: if the second time is less than the first one, add 86400 (= number of seconds in one day) to the result. But I must admit that I never bother.

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Timing a Calculation (97 SR-2)

    CalculateFull was introduced in XL 2000.
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Timing a Calculation (97 SR-2)

    Thanks for the confirmation, John.

  7. #7
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Louisville, Kentucky, USA
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Timing a Calculation (97 SR-2)

    So, is there any solution for me and my XL97?

  8. #8
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Timing a Calculation (97 SR-2)

    This should work in VB

    <pre>SendKeys "%^{f9}", True</pre>


    Steve

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Timing a Calculation (97 SR-2)

    In Xl 97 just:

    Application.Calculate
    -John ... I float in liquid gardens
    UTC -7ąDS

  10. #10
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Timing a Calculation (97 SR-2)

    I think this is just an F9 calc, not a full-blow ctrl-alt-f9

    Steve

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Timing a Calculation (97 SR-2)

    Right, I don't recall that Ctrl-Alt-F9 did anything different from F9 in XL97, but maybe I remember incorrectly. I'll check the old machine with 97 at home.
    -John ... I float in liquid gardens
    UTC -7ąDS

  12. #12
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Timing a Calculation (97 SR-2)

    F9 does a simple calc and if excel doesn't believe anything has changed it won't update.
    Ctrl-Alt-F9 forces a recalc on all.

    It becomes essential with some user-defined functions that are based on hidden rows, cell colors, etc (things excel does not believe will trigger different values) to make sure they are updated.

    Steve

  13. #13
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Louisville, Kentucky, USA
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Timing a Calculation (97 SR-2)

    I've never tried to figure what types of user-defined functions require ctrl-alt-f9, but whenever I use a UDF, I don't trust my results unless I do a ctrl-alt-f9.

    BTW, the Sendkeys function seems to do the trick. Thanks for solving a longstanding gripe.

  14. #14
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Timing a Calculation (97 SR-2)

    This site has some good general information on calculations in excel.

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •