I am trying to learn custom functions and could use help with this formula:
I am embarrassed to show my attempt but here it is anyway:
If you can show me where I went wrong I would really appreciate it!
Excel Formula:
=IF(E$2="ACTUAL",COUNTIFS(tblClsd[udAbbr],$B12,tblClsd[ClsDate],"<="&E$5,tblClsd[ClsDate],">"&D$5),"")
I am embarrassed to show my attempt but here it is anyway:
VBA Code:
Function CountClosedDeals(udAbbr As String, clsDateStart As Date, clsDateEnd As Date, actual As String) As Integer
Dim tbl As ListObject
Dim abbr As Range
Dim clsd As Range
Set tbl = Worksheets("tblClsd").ListObjects("tblClsd")
Set abbr = tbl.ListColumns("udAbbr").DataBodyRange
Set clsd = tbl.ListColumns("ClsDate").DataBodyRange
If actual = "ACTUAL" Then
CountClosedDeals = Application.WorksheetFunction.CountIfs(abbr, udAbbr, clsd, "<=" & clsDateEnd, clsd, ">" & clsDateStart)
Else
CountClosedDeals = ""
End If
End Function
If you can show me where I went wrong I would really appreciate it!