Consulting

Results 1 to 6 of 6

Thread: Solved: Function that's not working as should

  1. #1

    Solved: Function that's not working as should

    Hi Guys!

    I have a macro that is designed to look into a below function. The function should only pick dates from specified ranges which are same as current date (J1) and start date or following 6 workdays. Also if end date is >= current date then include. However the macro seems to be picking dates including those outside specified range. Can you please help and see if I have set my function correctly?

    [VBA]
    Function TaskActive(dtStartDate As Date, dtEndDate As Date) As Boolean
    If dtStartDate <= Application.WorksheetFunction.WorkDay(Range("J1").Value, 6) Or dtEndDate >= Range("J1").Value Then
    TaskActive = True
    Else
    TaskActive = False
    End If
    End Function[/VBA]

  2. #2
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    Ray,
    Your formula is not checking if the end date is greater than today, it is checking if the end date is greater than J1...

    [vba]
    If dtStartDate <= Application.WorksheetFunction.WorkDay(Range("J1").Value, 6) Or dtEndDate >= now() Then
    [/vba]
    HMMM upon further review, you posted J1 is current date... So you want it to fire if the start date is less than 6 work days greater than today and when the end date is >= today??? This means if the start date is 3 months ago, it will return true... is that what you want?

  3. #3
    Many thanks CodeNinja. J1 cell is where I have today ()

  4. #4
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    Ya, saw that ... read re-edit...

  5. #5
    Oh! Your message has just re-booted my brain I think the the function is working fine, just the conditions I hadn't set correctly.

    Many thanks CodeNinja!

  6. #6
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    Glad to help

Posting Permissions

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