示例数据显示在链接中
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 但似乎不起作用。
答案 0 :(得分:0)
如上所述,我认为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)