+ Reply to Thread
Results 1 to 8 of 8

Timer for Sub Proc

  1. #1
    Forum Contributor
    Join Date
    06-28-2018
    Location
    New York
    MS-Off Ver
    MS Office 2010
    Posts
    184

    Timer for Sub Proc

    Hi all,

    Hopefully this is an easy one. I have a main sub that runs and calls a second sub. Can I start a timer at the first sub and have it end/display when the second/called sub completes? If so can you please post a sample code? Thank you.

  2. #2
    Forum Contributor
    Join Date
    09-19-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    208

    Re: Timer for Sub Proc

    Have you tried Googling for "VBA Timer"? Pretty simple function to use, see here: https://www.thespreadsheetguru.com/t...macro-run-time

  3. #3
    Forum Contributor
    Join Date
    06-28-2018
    Location
    New York
    MS-Off Ver
    MS Office 2010
    Posts
    184

    Re: Timer for Sub Proc

    Quote Originally Posted by ¯\_(ツ)_/¯ View Post
    Have you tried Googling for "VBA Timer"? Pretty simple function to use, see here: https://www.thespreadsheetguru.com/t...macro-run-time
    That is actually where I pulled the code for the timer in the first sub. What I'm trying to do is start the timer when the first sub kicks off, and then carry it through to the end of the second sub which is called by the first sub.

  4. #4
    Forum Contributor
    Join Date
    09-19-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    208

    Re: Timer for Sub Proc

    So you'd place the "StartTime = Timer" at the beginning of your first sub, then the "SecondsElapsed" code immediately after the call to the second sub (assuming the first sub does additional tasks after the second sub ends).

    If that's not the case, you could probably use global public variables instead (stored in a standard module) and just set the start time at the start of sub1, and then just before exiting sub2, set an end time variable (or do the math to get the current time and subtract the original global variable).

  5. #5
    Forum Contributor
    Join Date
    06-28-2018
    Location
    New York
    MS-Off Ver
    MS Office 2010
    Posts
    184

    Re: Timer for Sub Proc

    No once the second sub ends that is it. So it is basically as follows:


    Sub 1 (variables and start timer)

    code here

    Call Sub2
    End Sub1
    _________
    Sub2

    code here

    End Sub2

  6. #6
    Forum Contributor
    Join Date
    09-19-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    208

    Re: Timer for Sub Proc

    Technically it doesn't matter that nothing else is executed in the second sub. Once the called sub (Sub2) completes, focus goes back to Sub1 to complete - in this case simply ending. You would still have the calculation done at the end of Sub1. See example below:
    Please Login or Register  to view this content.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Timer for Sub Proc

    Try this.

    1 Create a new Class module and call it CTimer

    2 Paste this code in the CTimer module.
    Please Login or Register  to view this content.
    3 To time your Sub2 try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  8. #8
    Forum Contributor
    Join Date
    06-28-2018
    Location
    New York
    MS-Off Ver
    MS Office 2010
    Posts
    184

    Re: Timer for Sub Proc

    Thanks all. I actually went with a version of the code posted by ¯\_(ツ)_/¯. Much appreciated.

    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)

Similar Threads

  1. timer for 30 minutes and timer based events
    By mohak12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2014, 06:20 PM
  2. Replies: 1
    Last Post: 12-12-2012, 08:46 PM
  3. Display Proc is text box
    By drawlings in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2006, 07:45 AM
  4. Replies: 1
    Last Post: 03-10-2006, 08:10 AM
  5. [SOLVED] Macro for OnKey: Can the proc name a VB6 proc?
    By im_chc in forum Excel General
    Replies: 1
    Last Post: 01-25-2006, 03:35 PM
  6. execte stored proc
    By maxzsim in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2005, 01:06 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