Consulting

Results 1 to 3 of 3

Thread: Break for next loop

  1. #1

    Break for next loop

    Hi all,

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

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

    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:

    [VBA]settledate = Sheets("Input").Cells(2, 9 + i).Value[/VBA]

    Let me know if this is not clear enough.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA]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[/VBA]

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why not just do

    [vba]

    i = 1
    Do
    If Sheets("Input").Cells(6, 9 + i).Value = "-" Then
    countdays = countdays + 1
    End If
    i = i + 1
    Loop Until countdays >= 3[/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •