早上好,我需要一些有关如何形成Excel公式以对2列与其他列中的值进行不同计数的帮助:
我想计算分配给“ ummu”的多个科目,但是再次出现相同的科目名称不应该计算在内。在此示例中,计数将返回4。如何使用excel公式实现此目标?
答案 0 :(得分:0)
以下是可以帮助您的功能:
Function CountUnique(SearchRange1 As Range, CriteriaRange1 As Range, SearchRange2 As Range, CriteriaRange2 As Range, Criteria As String) As Double
Dim MyArr1() As Variant, MyArr2() As Variant, MyArr3() As Variant, MyArr4() As Variant, Arr() As Variant, X As Double, Y As Double
MyArr1 = Application.Transpose(SearchRange1)
MyArr2 = Application.Transpose(CriteriaRange1)
MyArr3 = Application.Transpose(SearchRange2)
MyArr4 = Application.Transpose(CriteriaRange2)
ReDim Arr(0)
Arr(0) = ""
For X = LBound(MyArr1) To UBound(MyArr1)
If MyArr2(X) = Criteria And Not IsError(Application.Match(MyArr1(X), Arr, 0)) = False Then
ReDim Preserve Arr(UBound(Arr) + 1)
Arr(UBound(Arr)) = MyArr1(X)
End If
Next X
For Y = LBound(MyArr3) To UBound(MyArr3)
If MyArr4(Y) = Criteria And Not IsError(Application.Match(MyArr3(Y), Arr, 0)) = False Then
ReDim Preserve Arr(UBound(Arr) + 1)
Arr(UBound(Arr)) = MyArr3(Y)
End If
Next Y
CountUnique = UBound(Arr)
End Function
可能写得更好,但是,嘿,它是免费的:)
结果: