can Do Until be nested inside For Next?

r121a947

New member
Joined
Jun 29, 2019
Messages
49
Reaction score
0
Points
0
Excel Version(s)
Office 365
Can a Do Until loop be nested inside a For Next loop?

I have a For Next loop that was working, but when I tried to put a Do Until loop within the For Next, I get an error message "Next without For."

Thanks, in advance.
 
Yes you can. The error implies you haven't nested properly:
Code:
For i = 1 To 10
  Do
    'something
  Loop Until Z = x
Next i
or:
Code:
For i = 1 To 10
  Do Until Z = x
    'something
  Loop
Next i
 
This is the Do Until I am trying to use:

Code:
Do Until Cmatch = Cfind And Dmatch = Dfind And Ematch = Efind
        Cells.FindNext(After:=ActiveCell).Activate
        Exit Do
        Cells(ActiveCell.Row, 12).Value = Cells(ActiveCell.Row, 12).Value & " " & updFN

Thanks for your interest and help.
 
Code:
Do Until Cmatch = Cfind And Dmatch = Dfind And Ematch = Efind
  Cells.FindNext(After:=ActiveCell).Activate
Loop
Cells(ActiveCell.Row, 12).Value = Cells(ActiveCell.Row, 12).Value & " " & updFN
as long as the activate code in the middle changes one or more of Cmatch, Cfind, Dmatch, Dfind, Ematch, Efind.
 
Thank you.

Can I place additional instructions after Activate and before Loop?
 
Of course!
 
Thank you.

Works great!
 
Back
Top