PDA

View Full Version : Break for next loop



enfantter
09-26-2011, 05:22 AM
Hi all,

I have a loop i only want to run a specific number of times - is this possible ?

For i = 1 To 5
If Sheets("Input").Cells(6, 9 + i).Value = "-" Then
countdays = countdays + 1
End If
Next i

I only want to run this loop until countdays = 3 (example - alternatively some reference cell). I might have to use a do until loop, but I am not too familiar with that.

The thing is I want to record the date i up with. Dates are in row 2:

settledate = Sheets("Input").Cells(2, 9 + i).Value

Let me know if this is not clear enough.

Kenneth Hobs
09-26-2011, 05:32 AM
For i = 1 To 5
If Sheets("Input").Cells(6, 9 + i).Value = "-" Then
countdays = countdays + 1
End If
If countdays = 3 Then Exit For
Next i

Bob Phillips
09-26-2011, 05:42 AM
Why not just do



i = 1
Do
If Sheets("Input").Cells(6, 9 + i).Value = "-" Then
countdays = countdays + 1
End If
i = i + 1
Loop Until countdays >= 3