+ Reply to Thread
Results 1 to 2 of 2

Repeat Macro until condition is met

  1. #1
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Repeat Macro until condition is met

    Hi all, I have a relatively simply problem (I hope).

    In the attached file I have a macro (Macro 1) that generates a random number in cell W3 after 5 seconds.

    In cell K9, I have some code that checks to see if the random number in W3 - matches the fixed number in S3.

    What I want the macro to do, is repeat the calculation if the number does not match (so k9 shows a 0), to stop when it does match (so k9 shows a 1) but to wait 5 seconds between each new calculation - and allow me to still use the worksheet whilst the macro runs (in the background if possible)

    The macro I try just keeps looping and freezes the worksheet in between calculations.

    Please can someone help
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Repeat Macro until condition is met

    Worked it out for myself

    Sub Macro1()
    '
    ' Macro1 Macro
    '

    '


    Calculate
    DoEvents
    Application.Wait Now + TimeValue("00:00:05")


    End Sub


    Sub Rerun()
    With Sheets("Sheet1")
    ' Test Condition 1
    Do Until .Range("K9").Value = 1
    Application.Run "Macro1"
    Loop
    End With
    End Sub

+ 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. [SOLVED] Formula for duplicate referral - same condition or repeat within 30-90 days
    By jason_guest in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-02-2014, 02:27 AM
  2. Repeat Message box routine with IF condition and condnl formatting
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-18-2014, 02:39 AM
  3. Macro for repeat functions with if condition
    By mkanagaraj in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-23-2012, 02:08 AM
  4. Sum until a condition is met and repeat for a range
    By natattack in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-13-2012, 06:30 PM
  5. Condition format prevent no is repeat
    By choy96 in forum Excel General
    Replies: 2
    Last Post: 12-25-2011, 12:19 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