Do Until

Keith.Jackson

Board Regular
Joined
Mar 31, 2005
Messages
115
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
 

Some videos you may like

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
Joined
Sep 15, 2004
Messages
696
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
Joined
Mar 31, 2005
Messages
115
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
Joined
Apr 28, 2004
Messages
76,059
Office Version
  1. 365
Platform
  1. Windows
Can we see your current code?

And can you explain the actual purpose of the code?
 

Keith.Jackson

Board Regular
Joined
Mar 31, 2005
Messages
115

ADVERTISEMENT

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
Joined
Mar 31, 2005
Messages
115
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
Joined
Sep 15, 2004
Messages
696
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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,535
Messages
5,572,754
Members
412,482
Latest member
arooshrana2
Top