+ Reply to Thread
Results 1 to 6 of 6

Thread: VBA Do While Loop with multiple conditions

  1. #1
    Registered User
    Join Date
    01-21-2009
    Location
    Cambridge, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    VBA Do While Loop with multiple conditions

    Hi everyone,

    I'm having some problems getting a simple Do While loop to run. Essentially I'm trying to get it to run as long as one of two conditions is met, so I used an Or function in the loop condition.

    This then produces the "Run time error 1004: Application defined or Object defined error" error on that line.

    I'm certain my syntax for the two conditions is correct (one is a simple check value in a cell, the other is check the value of a VBA variable) so it would appear the error is caused by the inclusion of the Or function.

    So I guess my question is this, have I done something wrong? If so what and if possible why is what I did wrong (I like to understand these things)? Is this something that has to be done in a different way or even is it something that cannot be done?

    I'm using excel 2003 on XP SP3

    Thanks in advance for any responses.

    Cheers,

    Matt
    Last edited by barriecusvein; 01-28-2009 at 07:53 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,788

    Re: VBA Do While Loop with multiple conditions

    Matt - it could be any number of things but since none of us is psychic I suggest you post your code!

  3. #3
    Registered User
    Join Date
    01-21-2009
    Location
    Cambridge, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA Do While Loop with multiple conditions

    Apologies, should have posted it initially.

    Having spent a bit more time looking at it I found a method using find which eliminated the need for the loop.

    Sorry for time wasting and thanks for the quick response.

    Matt

  4. #4
    Registered User
    Join Date
    08-19-2009
    Location
    London, England
    MS-Off Ver
    Excel 2002
    Posts
    2

    Re: VBA Do While Loop with multiple conditions

    hi i would really like to hear what you did to solve this problem as I am faced with a very similar issue.
    i need to know how to code multiple conditions into a loop.
    i have the following code currently:

    Do Until ActiveCell.Value = "T"
    ActiveCell.Offset(1, 0).Select
    Loop

    but i need to add also if: ActiveCell.Value = ""
    and im not sure how to do it.

    anybody have any clue?

  5. #5
    Registered User
    Join Date
    01-21-2009
    Location
    Cambridge, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA Do While Loop with multiple conditions

    Quote Originally Posted by kedar View Post
    hi i would really like to hear what you did to solve this problem as I am faced with a very similar issue.
    i need to know how to code multiple conditions into a loop.
    i have the following code currently:

    Do Until ActiveCell.Value = "T"
    ActiveCell.Offset(1, 0).Select
    Loop

    but i need to add also if: ActiveCell.Value = ""
    and im not sure how to do it.

    anybody have any clue?
    I changed it from a Do While loop to a Do Until loop

    So for you it would be:

    Sub DoUntil()
        Do Until ActiveCell.Value = "" Or ActiveCell.Value = "T"
            ActiveCell.Offset(1, 0).Select
        Loop
    End Sub
    This will stop you on the cell containing the values specified

  6. #6
    Registered User
    Join Date
    08-19-2009
    Location
    London, England
    MS-Off Ver
    Excel 2002
    Posts
    2

    Re: VBA Do While Loop with multiple conditions

    thanks! that works perfectly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0