'Do Until...' Restart

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

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
 
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?
 
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
 
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 ...
 
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.
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top