PDA

View Full Version : Solved: Function that's not working as should



Ray.Mason
02-27-2013, 05:46 AM
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?


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

CodeNinja
02-27-2013, 07:07 AM
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...


If dtStartDate <= Application.WorksheetFunction.WorkDay(Range("J1").Value, 6) Or dtEndDate >= now() Then

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?

Ray.Mason
02-27-2013, 07:10 AM
Many thanks CodeNinja. J1 cell is where I have today ()
:)

CodeNinja
02-27-2013, 07:12 AM
Ya, saw that ... read re-edit...

Ray.Mason
02-27-2013, 07:36 AM
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!

CodeNinja
02-27-2013, 07:42 AM
Glad to help :wink: