我有一个函数,低于计算高于中值的值,但它计算A中高于中位数的所有值。我需要这个,当它达到6时停止计数。任何帮助都会很棒。
Function CountAbove(RangeToCountAbove As Range, _
MedianOfLastGroup As Double) As Long
Dim i As Double
Dim rows As Double
Dim cCell As Range
CountAbove = 0
For Each cCell In RangeToCountAbove
If (cCell.Value > MedianOfLastGroup) Then
CountAbove = CountAbove + 1
Else
Exit Function
End If
Next cCell
End Function
答案 0 :(得分:1)
正如@Comintern所写,将条件If CountAbove = 6
放在If
中,如下面编辑的代码所示:
Function CountAbove(RangeToCountAbove As Range, _
MedianOfLastGroup As Double) As Long
Dim i As Double
Dim rows As Double
Dim cCell As Range
CountAbove = 0
For Each cCell In RangeToCountAbove
If (cCell.Value > MedianOfLastGroup) Then
CountAbove = CountAbove + 1
If CountAbove = 6 Then Exit Function
Else
Exit Function
End If
Next cCell
End Function