-
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]
-
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?
-
Many thanks CodeNinja. J1 cell is where I have today ()
-
Ya, saw that ... read re-edit...
-
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!
-
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
-
Forum Rules