I have two UDF's both cause the problem...
Function Plan_Target(MCA_Value As String, CalcType As String, Optional Given_Month As String, Optional Given_Year As Integer) As Single
Application.Volatile
Dim RAW As ListObject
Set RAW = Sheets("Data").ListObjects("Table_awur_1")
If CalcType = "T" Then
'Target
Dim Prio(6) As Integer, x As Integer ' Create an array to store numbers
Prio(0) = 0 ' Not used, we do not have a priority 0
'Count the number of priority 1 - 5
For x = 1 To 5
Prio(x) = WorksheetFunction.CountIfs(Range("Planning_Sht[[#Data],[MCA]]"), MCA_Value, Range("Planning_Sht[[#Data],[Priority]]"), x)
Next x
'Calculate and Return Target
Plan_Target = ((Prio(1) * 9) + (Prio(2) * 6) + (Prio(3) * 3) + _
(Prio(4) * 2) + Prio(5)) / 6
Else
'Ensuring all criteria are met.
If Given_Month = "" Or IsNull(Given_Year) = True Then
Plan_Target = CVErr(xlErrValue)
End If
Dim This_Month As Date, Next_Month As Date
This_Month = Format(Given_Month & "/1/" & Given_Year, "mm/dd/yyyy")
If This_Month = "12/1/" & Given_Year Then
Next_Month = "1/1/" & Given_Year + 1
Else
Next_Month = DateAdd("d", 1, This_Month)
End If
'Preparation for calculation
If CalcType = "P" Then
'Planned
x = 7
ElseIf CalcType = "A" Then
'Achieved
x = 9
Else
'Cause an error if Plan_Target does not have a calculation type.
Plan_Target = CVErr(xlErrValue)
End If
'Calculation
Plan_Target = WorksheetFunction.CountIfs( _
RAW.ListColumns(3).Range, "NIEB", _
RAW.ListColumns(4).Range, "RED", _
RAW.ListColumns(5).Range, "=" & MCA_Value, _
RAW.ListColumns(x).Range, ">=" & This_Month, _
RAW.ListColumns(x).Range, "<" & Next_Month)
End If
End Function
and
Function PCM_Checker(SIG As String, WP As String, Given_Month As String, Given_Year As Integer, Optional MCA As String) As Integer
Application.Volatile
Dim RAW As ListObject
Set RAW = Sheets("Data").ListObjects("Table_awur_1")
Dim This_Month As Date, Next_Month As Date
This_Month = Format(Given_Month & "/1/" & Given_Year, "mm/dd/yyyy")
If This_Month = "12/1/" & Given_Year Then
Next_Month = "1/1/" & Given_Year + 1
Else
Next_Month = DateAdd("d", 1, This_Month)
End If
' If the SIG is "ACTIVE" then the MCA must be given
If SIG <> "* ACTIVE" Then
PCM_Checker = WorksheetFunction.SumIfs(RAW.ListColumns(10).Range, _
RAW.ListColumns(3).Range, "NIEB", _
RAW.ListColumns(4).Range, "RED", _
RAW.ListColumns(6).Range, SIG & " - " & WP, _
RAW.ListColumns(7).Range, ">=" & This_Month, _
RAW.ListColumns(7).Range, "<" & Next_Month)
ElseIf MCA <> "" Then
PCM_Checker = WorksheetFunction.SumIfs(RAW.ListColumns(10).Range, _
RAW.ListColumns(3).Range, "NIEB", _
RAW.ListColumns(4).Range, "RED", _
RAW.ListColumns(6).Range, SIG & " - " & WP, _
RAW.ListColumns(5).Range, "=" & MCA, _
RAW.ListColumns(7).Range, ">=" & This_Month, _
RAW.ListColumns(7).Range, "<" & Next_Month)
Else
PCM_Checker = CVErr(xlErrValue)
End If
End Function
Bookmarks