我正在尝试让 Application.WorksheetFunction.SumProduct wsf.CountIfs 与 4 个数组一起使用。到目前为止,我总是得到不正确的结果 a1 和 b1 :(
这是我的代码:
Dim lastrow As Long
Dim wsf
lastrow = Sheet2.Cells(Sheet2.Rows.Count, "M").End(xlUp).Row
Set wsf = Application.WorksheetFunction
Doctors = Array("Peter","Sam","Henry")
Emergency = Array("Y","N")
Specialty = Array("GP","Specialist")
Rank = Array("Senior","Junior")
a1 = Application.WorksheetFunction.SumProduct(wsf.CountIfs(Sheet2.Range("P2:P" & lastrow), Doctors, Sheet2.Range("M2:M" & lastrow), Emergency, Sheet2.Range("O2:O" & lastrow), Specialty, Sheet2.Range("R2:R" & lastrow), Rank))
b1 = Application.WorksheetFunction.SumProduct(wsf.SumIfs(Sheet2.Range("G2:G" & lastrow), Sheet2.Range("P2:P" & lastrow), Doctors, Sheet2.Range("M2:M" & lastrow), Emergency, Sheet2.Range("O2:O" & lastrow), Specialty, Sheet2.Range("R2:R" & lastrow), Rank))
我最好的办法是通过wsf.transpose仅使用 2 个标准:
a1 = Application.WorksheetFunction.SumProduct(wsf.CountIfs(Sheet2.Range("P2:P" & lastrow), Doctors, Sheet2.Range("M2:M" & lastrow), wsf.Transpose(Emergency)))
同样不适用于超过 2 个标准。
有什么线索吗?