Public Function GRIDSALES(rev_date As Date, grid_date As Date) As Variant
Application.Volatile (True)
Set Final_Price = Sheets("KRONOS").Range("$H:$H")
Set Team = Sheets("KRONOS").Range("$DO:$DO")
Set First_PD = Sheets("KRONOS").Range("$Q:$Q")
GRIDSALES1 = Application.WorksheetFunction.SumIfs( _
Final_Price _
, Team, "<>9" _
, First_PD, ">=" & rev_date, First_PD, "<=EoMonth(" & grid_date & ")")
End Function
上面的VBA代码没有任何错误,但没有生成答案。我正在尝试创建一个UDF,它将两个日期rev_date
和grid_date
之间的所有销售团队(不包括团队9)的最终价格相加。我错过了什么?
答案 0 :(得分:2)
鄙视“硬编码”sumif(antipattern?)的目标范围,即GRID SALES 1中的1和"<=EoMonth("
而不是Application.WorksheetFunction.EoMonth(grid_date, 0)
,sunifs的结果为double,应该是: / p>
Function ASALES(rev_date As Date, grid_date As Date) As Double
Dim Final_Price As Range
Dim Team As Range
Dim First_PD As Range
Application.Volatile (True)
Set Final_Price = Sheets("Sheet1").Range("H5:$H11")
Set Team = Sheets("Sheet1").Range("E5:E11")
Set First_PD = Sheets("Sheet1").Range("F5:F11")
ASALES = Application.WorksheetFunction.SumIfs( _
Final_Price _
, Team, "<>9" _
, First_PD, ">=" & rev_date _
, First_PD, "<=" & Application.WorksheetFunction.EoMonth(grid_date, 0))
End Function
答案 1 :(得分:1)
您的输出应该是函数名称。将GRIDSALES1更改为GRIDSALES。