我正在处理复杂的Excel VBA应用程序并尝试使用Countifs功能。问题是它给我一个类型不匹配错误我无法指出。在这里粘贴整个代码太复杂了,但我粘贴了我认为代码的相关行
Public NumSecTypes As Integer
Public NumSecurities As Integer
.
.
.
Dim i as Integer
Dim AvgPoSSizeCountif As Double
Dim SecType As String
.
.
.
Sheets("Output").Select
AvgPoSSizeCountif = WorksheetFunction.CountIfs(Range(Cells(i + 1, (17 + 2 * NumSecTypes)), Cells(i + 1, (16 + 2 * NumSecTypes + NumSecurities))), Range(Cells(6, (17 + 2 * NumSecTypes)), Cells(6, (16 + 2 * NumSecTypes + NumSecurities))), SecType, Range(Cells(i + 1, (21 + 2 * NumSecTypes + 2 * NumSecurities)), Cells(i + 1, (20 + 2 * NumSecTypes + 3 * NumSecurities))), ">0")
谁能告诉我这有什么问题?错误发生在“AvgPoSSizeCountif = ...”行
中非常感谢提前。任何帮助,将不胜感激。如果您需要任何其他信息,请告诉我
答案 0 :(得分:2)
CountIfs函数的语法应为
CountIfs( criteria_range1, criteria1, [criteria_range2, criteria2, ...])
看起来您缺少与参数1匹配的条件。这就是您的函数在下面的内容:
WorksheetFunction.CountIfs(
// Parameter 1
Range(Cells(i + 1, (17 + 2 * NumSecTypes)), Cells(i + 1, (16 + 2 * NumSecTypes + NumSecurities))),
// Parameter 2
Range(Cells(6, (17 + 2 * NumSecTypes)), Cells(6, (16 + 2 * NumSecTypes + NumSecurities))),
// Parameter 3
SecType,
// Parameter 4
Range(Cells(i + 1, (21 + 2 * NumSecTypes + 2 * NumSecurities)), Cells(i + 1, (20 + 2 * NumSecTypes + 3 * NumSecurities))),
// Parameter 5
">0"
)