Hi Folks.
I have the following worksheet function that I created:
=IF(U2="Complete", IF(ISNUMBER(SEARCH("Critical",$N2)), IF((NETWORKDAYS(C2,S2,P_Holidays)-1)>1,"No","Yes"),IF(ISNUMBER(SEARCH("High",$N2)), IF((NETWORKDAYS(C2,S2,P_Holidays)-1)>2,"No","Yes"),IF(ISNUMBER(SEARCH("Moderate",$N2)), IF((NETWORKDAYS(C2,S2,P_Holidays)-1)>3,"No","Yes"),IF(ISNUMBER(SEARCH("Low",$N2)), IF((NETWORKDAYS(C2,S2,P_Holidays)-1)>100,"No","Yes"))))),"N/A")
It works just fine - providing the user has the Analysis ToolPak add-in loaded.
I would like to create a UDF in Visual Basic for this function, but I'm having difficulty (most likely because I don't have much experience yet writing UDFs:)
To explain what the function does: It's purpose is to determine if the due date was met or not Our request queue has "submit date", "completion date", "status" and "priority" fields to fill out. The function first determines if the job is complete (if U2 -- Status -- is "Complete" - if not, it gets an N/A). Then it starts with the "Critical" status - Critical jobs have a one-day turnaround. So it uses the NetworkDays function to determine the length of time between the submit date and the completion date, then subtracts any company holidays (they are in a named range "P_Holidays"). If the networkdays is greater than one day, then due date was not met and you get a "No." If it was within the 24 hour time period, then you get a "Yes" for Due date Met.
Then it would continue checking "High" priority (which is a 2 day turnaround), then "Moderate" (3-day turnaround), then "Low" which actually has an open-ended turnaround time, but I limited it to 100 days.
I could write a macro to do formular1c1 to insert this into cell, but I'm concerned that the end user will not have the analysis tool pack loaded, hence my desire to create a UDF which will work without the need for an add-in.
'I started with this:
Function DueDateMet(SubmitDate As Date, ComplDate As Date, ReqPrior As String, _
ReqStatus As String) As String
Dim PHol As Range
Set PHol = Range("June.xls!P_Holidays")
Dim NetWorkD As Integer
NetWorkD = Application.NETWORKDAYS(SubmitDate, ComplDate, PHol)
'then this:
If ReqStatus = "Complete" And Left(ReqPrior, 8) = "Critical" And (NetWorkD - 1) > 1 Then
DueDateMet = "No"
Else
DueDateMet = "Yes"
End If
'I thought I would try to get just the "critical" status working, then add the rest, but so far, I'm just getting #VALUE!
Anyone who would like to direct some brain cells toward solving this, I would be greatly appreciated!
Thank you,
Gary