+ Reply to Thread
Results 1 to 10 of 10

How do I use VBA timer subroutines to start and stop random number generator?

  1. #1
    Registered User
    Join Date
    10-06-2008
    Location
    FL
    Posts
    5

    Unhappy How do I use VBA timer subroutines to start and stop random number generator?

    As you can see below, I've written code that writes random numbers into three columns of a spreadsheet (10 numbers in each column).

    What I want to do is create code that will run the random number generator for a period of 1 minute and then stop. I know that I will need to write a timer subroutine to do this but I'm how unsure how to do this. Can you help?

    Please Login or Register  to view this content.
    * the subroutine Workbook_SheetBeforeDoubleClick is meant to allow the user to interrupt the random number generator with a double mouse click and/or a right mouse click or some other event.
    Last edited by penn919; 10-06-2008 at 07:59 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Please read the Forum Rules, and then edit your post to wrap your code with Code Tags, and edit your thread title to be descriptive of your problem.

    Then we can help you with OnTime method.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    The title is a little verbose, but definitely better, thank you.

    Search the forum for ontime to find many examples. There is also a good example in VBE Help for the OnTime method. Post back if you get stuck.

  4. #4
    Registered User
    Join Date
    10-06-2008
    Location
    FL
    Posts
    5
    I'm sorry for sounding like a moron, but I don't really know how to implement this.

    Would it be like this:

    Please Login or Register  to view this content.
    Just for the sake of it, I'll let you know in advance that the above code doesn't work.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You want to run for a minute or until the sheet is double-clicked?

    You only need to do Randomize once, not each time before a number is generated ...

  6. #6
    Registered User
    Join Date
    10-06-2008
    Location
    FL
    Posts
    5
    Both.

    I want the the random number generator to run for 1 minute unless interrupted by double click.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Mayb like this.

    ThisWorkbook:
    Please Login or Register  to view this content.
    Code module:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-06-2008
    Location
    FL
    Posts
    5
    YES.

    However the code above dose not run for 1 minute, and it doesn't stop when I double click

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    I set it to run for 10 seconds (you change can the constant), and it does stop when I double-click.

    Do you have events enabled?

  10. #10
    Registered User
    Join Date
    10-06-2008
    Location
    FL
    Posts
    5
    Never mind.

    I didn't notice that you set the time to only 10 seconds, and I got the double click to work.

    thanks!

+ 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. Random number generator and matching all numbers
    By Zyphon in forum Excel General
    Replies: 2
    Last Post: 03-14-2008, 04:40 AM

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