[英]Excel array count frequencies with multiple conditions
example data is shown in the link 示例数据显示在链接中
https://docs.google.com/spreadsheets/d/1HXhT76CwDLs7XVPoU8uqx4RVrKOb6OOcox65l3i7LRY/edit#gid=0 https://docs.google.com/spreadsheets/d/1HXhT76CwDLs7XVPoU8uqx4RVrKOb6OOcox65l3i7LRY/edit#gid=0
desired outcome is "vcount" I want to use sumproduct function to count frequences , if the conditions is satisfied: 如果满足条件,则期望的结果是“ vcount”,我想使用sumproduct函数对频率进行计数:
① vyr>pyr ①vyr> pyr
② both v1 and v2 appears p1,p2,p3 columns(order does not matter) ②v1和v2都显示p1,p2,p3列(顺序无关紧要)
=SUMPRODUCT(--($G2:$I5=A2),--($G2:$I5=B2),--(C2>$J2:$J5)) then Ctrl + Shift + Enter = SUMPRODUCT(-($ G2:$ I5 = A2),-($ G2:$ I5 = B2),-(C2> $ J2:$ J5))然后按Ctrl + Shift + Enter
in fact, the real data contain about p1 to p20 columns , so i use CSE But doesn't seem to work. 实际上,实际数据包含大约p1至p20列,因此我使用CSE,但似乎不起作用。
As stated I think VBA is the only solution. 如上所述,我认为VBA是唯一的解决方案。 Put this in a module attached to the workbook.
将其放在工作簿附带的模块中。
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
Then you would call it like a normal formula: 然后,您可以将其称为普通公式:
=vcount(A2,B2,C2,$G$2:$I$5,$J$2:$J$5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.