SUMIFs function within VBA not working correctly
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开发者_如何学Python.SumIfs( _
Final_Price _
, Team, "<>9" _
, First_PD, ">=" & rev_date, First_PD, "<=EoMonth(" & grid_date & ")")
End Function
VBA code above complies without any error but does not generate an answer. I am trying to create a UDF that’s sums the Final Price for all sales teams (excluding team 9) between two dates rev_date
and grid_date
. What am I missing?
Despise "hardcode" the objetive range of the sumif (antipattern?) the 1 in GRIDSALES1 and "<=EoMonth("
instead of Application.WorksheetFunction.EoMonth(grid_date, 0)
, that sunifs is has results as double it should be as:
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
Your output should be the function name. Change GRIDSALES1 to GRIDSALES.
精彩评论