What is the correct syntax for a Do Until Loop? This is my first try attempting and I am getting an error message that says "Loop without Do". Here is what I have:
Dim i As Long
Do
For i = 3 To 93
Sheets("Analysis").Select
Range("B" & i).Copy
Range("R3").PasteSpecial
Sheets("Analysis").Select
Range("Q3").Copy
Range("G" & i).PasteSpecial Paste:=xlPasteValues
Loop Until Sheets("Analysis").Range("L1") < 50
Although I can't figure out what you are trying to acomplish with you loop, the code should be changed to the following in order to make it "correct".
Your code could use some real clean-up.
A couple of things. First, make sure that there's a mechanism somewhere that reduces the value in
.Range("L1")
to less than50
. Otherwise, this runs in an infinite loop (because you can't complete the condition to make it stop).Second, make sure that your
For
loops are closed withNext
. EitherNext
orNext x
wherex
is the iterator variable you defined should work (in your case,x
isi
).Third, read up on the differences of
Do While-Loop
,Do Until-Loop
,Do-Loop While
, andDo-Loop Until
.Until
andWhile
are pretty self-explanatory. The placement of the condition is a bit of a difficulty for those beginning with loops and should be mastered without question. One really clear explanation can be found here.Fourth, use
With
for sequential or simultaneous actions on a single object. Check this answer out for samples and explanations (check section (3)).Hope this helps.