Public Function Hours(project, plan_date As Date)
'Define the array of data to be used in function
Dim scheme_data As Variant
scheme_data = Sheets("TEST").Range("B2:P100")
'Define key dates of stages based on 'project'
Dim Gate_A2, Gate_B, Gate_C, ACL As Date
Gate_A2 = DateValue(Application.VLookup(project, scheme_data, 5, False))
Gate_B = DateValue(Application.VLookup(project, scheme_data, 6, False))
Gate_C = Application.VLookup(project, scheme_data, 9, False)
ACL = Application.VLookup(project, scheme_data, 11, False)
'Define what stage the project is in on 'plan_date'
Dim stage As Single
If plan_date < Gate_A2 Then
stage = 4.1
ElseIf plan_date < Gate_B Then
stage = 4.2
ElseIf plan_date < Gate_C Then
stage = 4.3
ElseIf plan_date < ACL Then
stage = 4.4
Else: stage = 4.5
End If
'Define the length in days of the curernt stage from dates in scheme_data
Dim stage_length As Integer
If stage = 4.2 Then
stage_length = Application.VLookup(project, scheme_data, 13, False)
ElseIf stage = 4.3 Then
stage_length = Application.VLookup(project, scheme_data, 14, False)
ElseIf stage = 4.4 Then
stage_length = Application.VLookup(project, scheme_data, 15, False)
Else: stage_length = 2
End If
'Check scheme_data to see if Engineer is the Lead, complexity of project and scope of in house assurance
Dim lead As String
Dim complex As String
Dim scope As String
lead = Application.VLookup(project, scheme_data, 2, False)
complex = Application.VLookup(project, scheme_data, 4, False)
scope = Application.VLookup(project, scheme_data, 3, False)
'Number of hours defined as total hours for current stage of project, divided by stage_lengh, converted from days to weeks
'Check if current stage is being covered in house, if not, return hours = 0
If stage = 4.2 Or stage = 4.3 Or (stage = 4.4 And scope = "whole scheme") Then
Hours = 7 * Application.VLookup(lead & complex & stage, Sheets("TEST").Range("W2:X19"), 2, False) / stage_length
Else: Hours = 0
End If
End Function
Thanks,
Bookmarks