+ Reply to Thread
Results 1 to 2 of 2

Do Until with Multiple Conditions

Hybrid View

  1. #1
    Butaambala
    Guest

    Do Until with Multiple Conditions

    Hello,

    Please help me to make my Do Until Loop work with multiple conditions.
    The outcome is correct using just one condtion (either works), but when
    I try to use both, the loop goes one too many iterations.


    Public Function SetNextDate()
    x = 1
    Set rng = Sheets("REF").Range("B1",
    Sheets("REF").Range("B1").End(xlDown))

    Do Until rng.Find(Date + x) Is Nothing And Weekday(Date + x, vbMonday)
    < 6
    x = x + 1
    Loop
    dteNextJulian = Date + x
    End Function


    Essentially, I want "Date" to increase by one day until "Date + x" is
    NOT a weekend day AND "Date + x" is NOT found in a list of special
    dates specified in "rng".

    Thank you in advance for your help!
    Ben.


  2. #2
    Toppers
    Guest

    RE: Do Until with Multiple Conditions

    Ben,
    It works OK for me with the data below. It finds 25/01/2006
    which meets your conditions. I omitted 22/01/06 (Sunday) and 25/01/06
    (Wednesday).

    Your last statement should be:

    SetNextDate = Date + x NOT dteNextJulian = Date + x (Typo?!)


    (XL2003)

    21/01/2006
    23/01/2006
    24/01/2006
    26/01/2006
    28/01/2006
    29/01/2006
    30/01/2006
    31/01/2006
    01/02/2006
    02/02/2006

    "Butaambala" wrote:

    > Hello,
    >
    > Please help me to make my Do Until Loop work with multiple conditions.
    > The outcome is correct using just one condtion (either works), but when
    > I try to use both, the loop goes one too many iterations.
    >
    >
    > Public Function SetNextDate()
    > x = 1
    > Set rng = Sheets("REF").Range("B1",
    > Sheets("REF").Range("B1").End(xlDown))
    >
    > Do Until rng.Find(Date + x) Is Nothing And Weekday(Date + x, vbMonday)
    > < 6
    > x = x + 1
    > Loop
    > dteNextJulian = Date + x
    > End Function
    >
    >
    > Essentially, I want "Date" to increase by one day until "Date + x" is
    > NOT a weekend day AND "Date + x" is NOT found in a list of special
    > dates specified in "rng".
    >
    > Thank you in advance for your help!
    > Ben.
    >
    >


+ 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