我做了一些宏,我升級了Diedrich的一個宏,在excel 2010中有一個MaxIfs,它與行代碼放在一起。我需要幫助來創建miniifs vba功能?
Public Function maxifs(MaxRange As Range, ParamArray Criteria() As Variant) As Variant
Application.Volatile
Dim n As Long
Dim i, j As Long
Dim c As Variant
Dim f As Boolean
Dim w() As Long
Dim k As Long
Dim z As Variant
'Error if less than 1 criteria
On Error GoTo ErrHandler
n = UBound(Criteria)
If n < 1 Then
'too few criteria
GoTo ErrHandler
End If
'Define k
k = 0
'Loop through cells of max range
For i = 1 To MaxRange.Count
For j = 1 To MaxRange.Count
'Start by assuming there is a match
f = True
'Loop through conditions
For c = 0 To n - 1 Step 2
'Does cell in criteria range match condition?
If Criteria(c).Cells(i, j).Value <> Criteria(c + 1) Then
f = False
End If
Next c
'Define z
z = MaxRange
'Were all criteria satisfied?
If f = True Then
k = k + 1
ReDim Preserve w(k)
w(k) = z(i, j)
End If
Next j
Next i
maxifs = Application.Max(w)
Exit Function
ErrHandler:
maxifs = CVErr(xlErrValue)
End Function
所以現在我會做minifs,如果我所有的價值都是正面的,那麼它不起作用。
我該怎麼辦?
PS:如果你在這個宏最大的位數的變化,將工作太
謝謝您的回答。
難道我們要明白,功能maxifs作品,但沒有按minifs 「T?那麼,非工作代碼在哪裏?你能澄清一下嗎? – ccprog