+ Reply to Thread
Results 1 to 8 of 8

Restarting a running VBA macro on cell value exceeding limits

  1. #1
    Registered User
    Join Date
    04-06-2012
    Location
    India
    MS-Off Ver
    Pro Plus 2019
    Posts
    86

    Restarting a running VBA macro on cell value exceeding limits

    Hi!

    I have a VBA Code that starts on workbooks open and refreshes data every 10 seconds in a new row.
    However, given the amount of calculations, sometimes the VBA hangs.

    I was wondering whether I could modify the code below to restart every time the difference between current time and the last update time exceeds or falls below a certain margin, maybe 30 seconds + or (-).

    Please Login or Register  to view this content.
    Thanx,

    Naira
    Last edited by naira; 08-11-2013 at 03:56 PM.

  2. #2
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Restarting a running VBA macro on cell value exceeding limits

    how quickly is data being fed into the Live data sheet?
    also why have the timer run the macro every 1 second to check if 10 seconds has passed instead of using a 10 second timer?

  3. #3
    Registered User
    Join Date
    04-06-2012
    Location
    India
    MS-Off Ver
    Pro Plus 2019
    Posts
    86

    Re: Restarting a running VBA macro on cell value exceeding limits

    Quote Originally Posted by Leon V (AW) View Post
    how quickly is data being fed into the Live data sheet?
    also why have the timer run the macro every 1 second to check if 10 seconds has passed instead of using a 10 second timer?
    Hi!
    Thanx for your reply.

    - The data is fed into the Live data sheet every second.
    - Why is timer is run every 1 second? If you are referring to
    Please Login or Register  to view this content.
    then data will be updated only when I open the workbook and not every 10 seconds if I change it to
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Restarting a running VBA macro on cell value exceeding limits

    I put it on a 10 second timer and it seems to run fine. see bellow.
    Please Login or Register  to view this content.
    a bit of optimising and:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-06-2012
    Location
    India
    MS-Off Ver
    Pro Plus 2019
    Posts
    86

    Re: Restarting a running VBA macro on cell value exceeding limits

    Hi Leon,

    Appreciate your help in optimizing the code and it does look simple and elegant.

    However, I am still not sure how to restart the code incase the code stops executing for more than a particular no. of seconds.
    I was wondering for something like if I could put the value in Cell H1 and the code could check +/ - of that time and restart in case it is exceeded by the no. of seconds as displayed in cell I3.

    Thanx again for your help though.

    PS: Your reply did answer my request for help on the above VBA code posted at http://www.excelforum.com/excel-prog...new-sheet.html. Will mark that thread as Solved

    Naira
    Last edited by naira; 08-08-2013 at 01:47 PM.

  6. #6
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Restarting a running VBA macro on cell value exceeding limits

    If you are asking for a way to moniter the running code for any "lag", I don't think this can be done within Excel as anything implimented to moniter the macro would be halted by the "lag" also (sort of like asking someone to tell you when they are asleep).
    However I don't see why this code would "lag" the timer might fail if the rest of the code took more than 10 seconds to run but copying 7 cells takes milliseconds even doing it 1 cell at a time like in your code.

  7. #7
    Registered User
    Join Date
    04-06-2012
    Location
    India
    MS-Off Ver
    Pro Plus 2019
    Posts
    86

    Re: Restarting a running VBA macro on cell value exceeding limits

    Hi Leon,

    Actually I was thinking that another macro would be looking at the time difference between the cell having my cut-off time lag and the time lag as shown for the last update and if the time lag went beyond a certain time period, the new macro would stop the above macro and restart it.

    Also, the cells being updated are not 7, but more like 2000 cells for around 500 parameters. The sample file was just a basic sample file of concept.

    Anyways, marking this thread as solved. If I still see any problems in the actual run, I know I can always get help on this forum.

    Thanks a lot for your help once again.

    Regards,

    Naira

  8. #8
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Restarting a running VBA macro on cell value exceeding limits

    Hi naira
    A single instance of Excel only has one thread for VBA so macro A cannot continuosly run while macro B continuosly moniters a cell/value. In order to run macro B macro A must pause which can only be done with a line saying "pause and run macro B", if macro A has lagged then it will be delayed in reaching that line so macro B will not be prompted to check the cell.

    what you could do if the timer is expiring before the macro is finished its current run is place the timer at the end of the script.

+ 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. Pausing and restarting a macro with OnKey method
    By HitTheEXCELerator in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2013, 07:46 PM
  2. Pausing and restarting a macro using a button
    By Bonnister in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2012, 03:43 PM
  3. Exceeding text limits
    By Dieter in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-05-2008, 03:37 AM
  4. restarting a calculation based on a cell value
    By bwright in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-26-2007, 10:58 PM
  5. [SOLVED] Restarting a macro
    By BR in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 12-23-2005, 06:00 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