Results 1 to 3 of 3

Thread: Loop with multiple critiria

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    18

    Loop with multiple critiria

    I’m having problems with a loop that copies rows to a different sheet if a condition is met. The loop works for the first condition but doesn’t seem to move to the next condition or part of the loop. Whatever I do either turns into an endless loop or is missing part of the code to execute. The following is a sample of the code I’m using with two of the seven conditions I want it to find and copy to another sheet. Thanks for any help.

    'loop to Repair list

    'Pressure

    Set i = Sheets("Bad")
    Set e = Sheets("Repair List")
    Dim d
    Dim j
    d = 1
    j = 2

    Do Until IsEmpty(i.Range("A" & j))

    If i.Range("D" & j).Value = 0 Then
    d = d + 1
    e.Rows(d).Value = i.Rows(j).Value
    End If
    j = j + 1
    Loop

    'Water Level



    Do
    If i.Range("E" & j).Value < 11.1 Then
    d = d + 1
    e.Rows(d).Value = i.Rows(j).Value

    End If
    j = j + 1
    Loop

    End Sub

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Loop with multiple critiria

    The second Do isn't doing until something.

    If your first case, you are saying
    Code:
    Do Until IsEmpty(i.Range("A" & j))
    In your second, you are just saying "Do" - Do what until when?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    18

    Re: Loop with multiple critiria

    In the second case I want it to Do -

    If i.Range("E" & j).Value < 11.1 Then
    d = d + 1
    e.Rows(d).Value = i.Rows(j).Value

    Until IsEmpty(i.Range("A" & j))

    Just like in the first case.

Posting Permissions

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



Click Here to Expand Forum to Full Width