+ Reply to Thread
Results 1 to 8 of 8

VBA DoEvents function 'magic'

  1. #1
    Registered User
    Join Date
    08-14-2012
    Location
    Vancouver, BC, Canukistan
    MS-Off Ver
    12
    Posts
    21

    VBA DoEvents function 'magic'

    ...for anyone having problems ending long loops. One way of doing is to use the DoEvents VBA function only I found that there is a great deal of confusion about it on the Internet. I figured it out myself and, I thought, others might benefit from my experience.

    As such, I wrote a small Excel file with three identical tabs. They each contain a counter with a 'start', 'stop' and 'reset' button. They are all independently controlled while the user still has control - although limited somewhat - of the spreadsheet.

    Have a look and let me know what you think: 2012.11.09...MS Excel VBA DoEvents function-demo.xls

    I was even able to bring up a live VBA editor, rename the tabs of the running counters, etc!!! I'm quite impressed with the DoEvents function.
    Last edited by danleonida; 11-10-2012 at 05:41 PM. Reason: spell/add paragraph/change title and first paragraph

  2. #2
    Registered User
    Join Date
    08-14-2012
    Location
    Vancouver, BC, Canukistan
    MS-Off Ver
    12
    Posts
    21

    Re: VBA DoEvents function 'magic'

    protonLeah,

    I noticed you deleted your own post requesting that I change the title of this thread. I changed it to "VBA DoEvents help available..." followed by a new paragraph which is still present in the opening post. The title has been reverted back to the original.

    Am I to understand that you downloaded the file at the end of the link and liked it?

    I also noted that the tread has been moved to "Forum > Off Topic > Tips and Tutorials". I was looking for something like it before the original post and failed. Sorry!

  3. #3
    Registered User
    Join Date
    08-14-2012
    Location
    Vancouver, BC, Canukistan
    MS-Off Ver
    12
    Posts
    21

    Re: VBA DoEvents function 'magic'

    I've added some bells/whistles to the file as well as simplifying it a bit!

    I thought you might enjoy:

    2012.11.14...MS Excel VBA DoEvents function-demo II.xls

  4. #4
    Registered User
    Join Date
    08-14-2012
    Location
    Vancouver, BC, Canukistan
    MS-Off Ver
    12
    Posts
    21

    Re: VBA DoEvents function 'magic'

    I've added to the file a circle area calculator to see how my favorite VBA function interacts with the spreadsheet. Here's the file:

    2012.11.15...MS Excel VBA DoEvents function-demo III.xls

    It has a small message box explaining what to do to highlight what I believe is an 'undocumented feature' of the DoEvents function.

    I suspected the few global variables I was using were behind the misbehavior, so I eliminated and replaced them with named cells in the spreadsheet. It made no difference! The resulting file runs slower but still exhibits the 'undocumented feature'. Here's the file with no globals:

    2012.11.15...MS Excel VBA DoEvents function-demo IV.xls

    I think the function DoEvents is too useful not to be well studied!

  5. #5
    Registered User
    Join Date
    08-14-2012
    Location
    Vancouver, BC, Canukistan
    MS-Off Ver
    12
    Posts
    21

    Re: VBA DoEvents function 'magic'

    Found a small bug in my macros and fixed it. If one were to click 'start' several times, the macro/spreadsheet would crash! Here's the fixed up version:

    2012.11.15...MS Excel VBA DoEvents function-demo V.xls

    It seems that if one needs to calculate the area of a circle, Excel will be glad to oblige but IT WILL NOT RETURN CONTROL to the DoEvents statement for some reason! Go figure!

  6. #6
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: VBA DoEvents function 'magic'

    I'm really interested in this, but I cna't download the files from the website. Can you make (just the last?) version available through this website?
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  7. #7
    Registered User
    Join Date
    08-14-2012
    Location
    Vancouver, BC, Canukistan
    MS-Off Ver
    12
    Posts
    21

    Re: VBA DoEvents function 'magic'

    I tried the link in the post right above yours and had no problems.

    You have to click the smaller of the two 'download' buttons.

    I have attached the file to this post, but I don't know id it will work since I've never used the feature before. I also included a simple and useful (to yours truly) timer that also puts the DoEvents function to good use.

    If you still have problems, drop me a line and I'll send them by email.

    Good luck! and...

    Be good and do disturb!
    Not disturbed enough yet!

    danleonida-at-yahoo-dot-com
    P.S.

  8. #8
    Registered User
    Join Date
    08-14-2012
    Location
    Vancouver, BC, Canukistan
    MS-Off Ver
    12
    Posts
    21

    Re: VBA DoEvents function 'magic'

    Quote Originally Posted by Cheeky Charlie View Post
    ... Can you make (just the last?) version available through this website?
    You are welcome, Charlie!

    Be good and do disturb!
    Not disturbed enough yet!

    danleonida-at-yahoo-dot-com

+ 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