Welcome Guest
Log In | Register )
You last visited December 8, 2016, 3:03 pm
All times shown are
Eastern Time (GMT-5:00)

MS Excel Macro with loop

Topic closed. 3 replies. Last post 6 years ago by Irvin.

Page 1 of 1
PrintE-mailLink
Irvin's avatar - Goolag

New Zealand
Member #2234
September 2, 2003
173 Posts
Offline
Posted: June 26, 2010, 9:57 am - IP Logged

Hello All,

I am trying to create a macro which will loop until the specified cell comes back false.

So the cell is J3

And the function is calculate

I want it to keep recalculating until cell J3 is false.

Sorry I just dont understand macros. Any help would be appreciated.

 

Thanks, Irvin

    Avatar

    United States
    Member #41846
    June 23, 2006
    459 Posts
    Offline
    Posted: June 26, 2010, 8:28 pm - IP Logged

    Hello All,

    I am trying to create a macro which will loop until the specified cell comes back false.

    So the cell is J3

    And the function is calculate

    I want it to keep recalculating until cell J3 is false.

    Sorry I just dont understand macros. Any help would be appreciated.

     

    Thanks, Irvin

    Irvin

    your request is too vague to give you specific help. using Microsoft's help within Excel, can get you examples of how to use a command.

    What you see below is a copy of a help page.  you mentioned you were trying to use macros. for something like this you will probably have to write your macro in VBA. VBA is easy if you have done any programming or are willing to learn a few commands or statements

    Do...Loop Statement Example

    This example shows how Do...Loop statements can be used. The inner Do...Loop statement loops 10 times, sets the value of the flag to False, and exits prematurely using the Exit Do statement. The outer loop exits immediately upon checking the value of the flag.

     

    Dim Check, Counter Check = True: Counter = 0 ' Initialize variables. Do ' Outer loop. Do While Counter < 20 ' Inner loop. Counter = Counter + 1 ' Increment Counter. If Counter = 10 Then ' If condition is True. Check = False ' Set value of flag to False. Exit Do ' Exit inner loop. End If Loop Loop Until Check = False ' Exit outer loop immediately. 

    Do...Loop Statement Example

    This example shows how Do...Loop statements can be used. The inner Do...Loop statement loops 10 times, sets the value of the flag to False, and exits prematurely using the Exit Do statement. The outer loop exits immediately upon checking the value of the flag.

     Dim Check, CounterCheck = True: Counter = 0    ' Initialize variables.Do    ' Outer loop.    Do While Counter < 20    ' Inner loop.        Counter = Counter + 1    ' Increment Counter.        If Counter = 10 Then    ' If condition is True.            Check = False    ' Set value of flag to False.            Exit Do    ' Exit inner loop.        End If    LoopLoop Until Check = False    ' Exit outer loop immediately.
      Irvin's avatar - Goolag

      New Zealand
      Member #2234
      September 2, 2003
      173 Posts
      Offline
      Posted: June 27, 2010, 7:16 am - IP Logged

      Sorry if I am a bit vague.

      I have a formula in the cell J3 which generates a random number. This number is then checked against a database. If it matches then the answer comes back true. So basically I am hitting calculate all the time until it generates a random number that comes back false. So I thought it would be easier to do a loop so it will keep calculating until false. I will try the loop function you mentioned above.

       

      Thank you.

        Irvin's avatar - Goolag

        New Zealand
        Member #2234
        September 2, 2003
        173 Posts
        Offline
        Posted: June 27, 2010, 9:50 am - IP Logged

        Alright I used the "Do until" loop and it works a treat.

         

        Thank you