[英]Excel array count frequencies with multiple conditions
示例数据显示在链接中
https://docs.google.com/spreadsheets/d/1HXhT76CwDLs7XVPoU8uqx4RVrKOb6OOcox65l3i7LRY/edit#gid=0
如果满足条件,则期望的结果是“ vcount”,我想使用sumproduct函数对频率进行计数:
①vyr> pyr
②v1和v2都显示p1,p2,p3列(顺序无关紧要)
= SUMPRODUCT(-($ G2:$ I5 = A2),-($ G2:$ I5 = B2),-(C2> $ J2:$ J5))然后按Ctrl + Shift + Enter
实际上,实际数据包含大约p1至p20列,因此我使用CSE,但似乎不起作用。
如上所述,我认为VBA是唯一的解决方案。 将其放在工作簿附带的模块中。
Function vcount(v1 As Range, v2 As Range, vyr As Range, pRng As Range, pyr As Range) As Long
vcount = -1
Dim pArr As Variant
pArr = pRng.Value
Dim pyrArr As Variant
pyrArr = pyr.Value
If UBound(pArr, 1) <> UBound(pyrArr, 1) Then Exit Function
Dim temp As Long
temp = 0
Dim i As Long
For i = LBound(pArr, 1) To UBound(pArr, 1)
Dim v1B As Boolean
v1B = False
Dim v2B As Boolean
v2B = False
Dim j As Long
For j = LBound(pArr, 2) To UBound(pArr, 2)
If pArr(i, j) = v1 Then v1B = True
If pArr(i, j) = v2 Then v2B = True
Next j
If v1B And v2B And pyrArr(i, 1) < vyr Then temp = temp + 1
Next i
vcount = temp
End Function
然后,您可以将其称为普通公式:
=vcount(A2,B2,C2,$G$2:$I$5,$J$2:$J$5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.