# Do Until

#### Keith.Jackson

##### Board Regular
I want to run a "Do Until" procedure on a range of values. I am having trouble with the first part.
I want to pick From 20 cells Sheets("Sheet2").Range ("D1:D20")
and run the procedure after picking each value in order from top to bottom.
How do I write the code to pick the first value in the range , run the Do Until and then pick the next value in the range until the value = 0?

Thanks

### Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

#### a7n9

##### Well-known Member
You can place your Do Loop inside a For Each Loop
For e.g.,

For Each c In Range("D1:D20")
Do Untill

Loop

Next C

#### Keith.Jackson

##### Board Regular
How do I make the loop stop. If I make C=0 the loop doesn't run. If I make it equal to anything else, it keeps on running.

#### Norie

##### Well-known Member
Can we see your current code?

And can you explain the actual purpose of the code?

#### Keith.Jackson

##### Board Regular

Sub Send()
Do Until C = 0
For Each C In Sheets("Sheet2").Range("D2:D20")

Sheets("Sheet2").Range("C34").Value = C
Next C
Loop

End Sub

#### Keith.Jackson

##### Board Regular
After the value is copied to Sheet2 range C34, there is another procedure in the loop, but I have to make the loop stop befor I put the other procedure in.

#### a7n9

##### Well-known Member
Instead of using Do Until, you can use a For Loop and an Exit for.

For e.g.,

For Each C In Sheets("Sheet2").Range("D2:D20")
Sheets("Sheet2").Range("C34").Value = C
If c = 0 Then Exit For
Next C

Replies
1
Views
343
Replies
10
Views
201
Replies
8
Views
337
Replies
1
Views
221
Replies
2
Views
150