+ Reply to Thread
Results 1 to 2 of 2

Using For loop to condition

  1. #1
    Registered User
    Join Date
    05-16-2005
    Posts
    11

    Using For loop to condition

    Is it ok to use a For loop to look to condition? I'm trying to loop over a range for something like this

    For prodcntr = 24 To Cells(1, 1).FindFormat.Interior.Pattern = xlGray25
    If Worksheets("Schedule").Cells(prodcntr, 2) <> "" And Worksheets("Schedule").Cells(prodcntr, 2) > 0 Then
    prodlgnth = prodlgnth + 1

    End If

    Next prodcntr

    I'm trying to make the range for the loop more dynamic.

  2. #2
    Charlie
    Guest

    RE: Using For loop to condition

    A For-Next loop is intended to start at one numeric value and end at another,
    either incrementing or decrementing by a numeric value. Examples:

    For i = 1 To 10
    Next i

    For i = 10 To 1 Step -1
    Next i

    For i = iStart To iEnd Step 2
    Next i

    etc.

    but you can test for a condition inside the loop and exit like this:

    For i = 24 To Whatever
    If Cells(i, 1).FindFormat.Interior.Pattern = xlGray2 Then Exit For
    Next i


    "bundyloco" wrote:

    >
    > Is it ok to use a For loop to look to condition? I'm trying to loop over
    > a range for something like this
    >
    > For prodcntr = 24 To Cells(1, 1).FindFormat.Interior.Pattern =
    > xlGray25
    > If Worksheets("Schedule").Cells(prodcntr, 2) <> "" And
    > Worksheets("Schedule").Cells(prodcntr, 2) > 0 Then
    > prodlgnth = prodlgnth + 1
    >
    > End If
    >
    > Next prodcntr
    >
    > I'm trying to make the range for the loop more dynamic.
    >
    >
    > --
    > bundyloco
    > ------------------------------------------------------------------------
    > bundyloco's Profile: http://www.excelforum.com/member.php...o&userid=23386
    > View this thread: http://www.excelforum.com/showthread...hreadid=397292
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1