+ Reply to Thread
Results 1 to 6 of 6

'Do Until...' Restart

  1. #1
    Jack
    Guest

    'Do Until...' Restart

    How can I restart 'Do Until' loop within the same macro?

    I have :-

    Do Until Range("a1") = 100
    ..
    ..
    Loop
    A1 is always an integer and will increment depending on other calculations
    but not necessarily in constant steps.
    For example it could = 95, 96, 98, 101 but I need the macro to stop at
    exactly A1=100 so I need to restart the Do Until if A1 > 100 - but how.

    Thanks
    Jack





  2. #2

    Re: 'Do Until...' Restart

    Perhaps I'm missing something, but do until value = 100 SHOULD run
    UNTIL the value is EQUAL TO ONE HUNDRED - so you shouldn't need to
    restart it?

    Jack wrote:
    > How can I restart 'Do Until' loop within the same macro?
    >
    > I have :-
    >
    > Do Until Range("a1") = 100
    > .
    > .
    > Loop
    > A1 is always an integer and will increment depending on other calculations
    > but not necessarily in constant steps.
    > For example it could = 95, 96, 98, 101 but I need the macro to stop at
    > exactly A1=100 so I need to restart the Do Until if A1 > 100 - but how.
    >
    > Thanks
    > Jack



  3. #3
    Jack
    Guest

    Re: 'Do Until...' Restart

    Thanks for replying.

    The macro should stop when A1 = [exactly] 100
    But A1 could increment, for example, from 99 to 101 and thus skip being =
    100

    Thanks
    Jack

    <[email protected]> wrote in message
    news:[email protected]...
    > Perhaps I'm missing something, but do until value = 100 SHOULD run
    > UNTIL the value is EQUAL TO ONE HUNDRED - so you shouldn't need to
    > restart it?
    >
    > Jack wrote:
    >> How can I restart 'Do Until' loop within the same macro?
    >>
    >> I have :-
    >>
    >> Do Until Range("a1") = 100
    >> .
    >> .
    >> Loop
    >> A1 is always an integer and will increment depending on other
    >> calculations
    >> but not necessarily in constant steps.
    >> For example it could = 95, 96, 98, 101 but I need the macro to stop at
    >> exactly A1=100 so I need to restart the Do Until if A1 > 100 - but how.
    >>
    >> Thanks
    >> Jack

    >




  4. #4

    Re: 'Do Until...' Restart

    Hi Jack,

    Try this macro:

    Sub Stop_At_100()

    Range("A1").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[1]C:R[199]C)"
    Range("A2").FormulaR1C1 = "1"

    Do Until Range("a1") = 100
    Dim x As Range
    Set x = Range("a1").End(xlDown).Offset(1, 0)
    x.FormulaR1C1 = "=+R[-1]C"
    Loop

    End Sub

    It stops when cell A1 = 100. Could be that your calculation is not
    exactly "100" ... maybe 100.00001 or something like that. Your should
    try rounding cell "A1" so it hits exactly 100.

    Regards ...


  5. #5

    Re: 'Do Until...' Restart

    Re-reading the question, I think you are asking to reset the value of
    A1? If so, include in the loop some code that says if A1>100 then
    a1=whatever you want.

    [email protected] wrote:
    > Hi Jack,
    >
    > Try this macro:
    >
    > Sub Stop_At_100()
    >
    > Range("A1").Select
    > ActiveCell.FormulaR1C1 = "=SUM(R[1]C:R[199]C)"
    > Range("A2").FormulaR1C1 = "1"
    >
    > Do Until Range("a1") = 100
    > Dim x As Range
    > Set x = Range("a1").End(xlDown).Offset(1, 0)
    > x.FormulaR1C1 = "=+R[-1]C"
    > Loop
    >
    > End Sub
    >
    > It stops when cell A1 = 100. Could be that your calculation is not
    > exactly "100" ... maybe 100.00001 or something like that. Your should
    > try rounding cell "A1" so it hits exactly 100.
    >
    > Regards ...



  6. #6
    Bob Phillips
    Guest

    Re: 'Do Until...' Restart

    Maybe something like

    Do Until Range("A1").Value = 100
    Range("A1").Value = 0 '<<<<<<<<< change to initial value
    Do Until Range("A1").Value >= 100
    'your stuff
    Loop
    Loop

    --

    HTH

    Bob Phillips

    (replace xxxx in the email address with gmail if mailing direct)

    "Jack" <[email protected]> wrote in message
    news:[email protected]...
    > How can I restart 'Do Until' loop within the same macro?
    >
    > I have :-
    >
    > Do Until Range("a1") = 100
    > .
    > .
    > Loop
    > A1 is always an integer and will increment depending on other

    calculations
    > but not necessarily in constant steps.
    > For example it could = 95, 96, 98, 101 but I need the macro to stop at
    > exactly A1=100 so I need to restart the Do Until if A1 > 100 - but how.
    >
    > Thanks
    > Jack
    >
    >
    >
    >




+ 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