+ Reply to Thread
Results 1 to 2 of 2

Multiple Condition Do Loop

Hybrid View

redpanda Multiple Condition Do Loop 07-01-2011, 02:02 PM
Leith Ross Re: Multiple Condition Do Loop 07-01-2011, 02:29 PM
  1. #1
    Registered User
    Join Date
    05-02-2010
    Location
    Houston
    MS-Off Ver
    Excel 2003
    Posts
    5

    Multiple Condition Do Loop

    I have spent sometime searching for why this isn't working but to no avail...

    What I am trying to do is loop through a column of data until condition 1 is met then check if condition 2 is met 4 cells to the left. Below is the code, if I change the "And" to "Or" it works when either condition is met but if it is "And" it doesn't. Thank you for the help!

    Range("G5").Select
    Do
    If Selection.Value = Range("M4") And Selection.Offset(0, -4) = Range("I4") Then
    Range(Selection.Offset(0, -4), Selection).Copy
    Else
    Selection.Offset(1, 0).Select
    End If
    Loop
    Last edited by Leith Ross; 07-01-2011 at 02:25 PM. Reason: Changed Quote Tags to Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Multiple Condition Do Loop

    Hello redpanda,

    You need to check that the first condition is true before check the next condition. You will need a nested If...Then to do this. Try this revision.
    Range("G5").Select
      Do
        If Selection.Value = Range("M4") Then
    
          If  Selection.Offset(0, -4) = Range("I4") Then
             Range(Selection.Offset(0, -4), Selection).Copy
          End If
    
        Else
          Selection.Offset(1, 0).Select
        End If
      Loop
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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