Boa noite!!
Outras versões...
UDF....
Public Function MaxIF(criteriaRange As Range, searchValue As Variant, calcRange As Range)
AciveCell.Formula = "=SumProduct(Max((criteriaRange = searchValue) * (calcRange)))"
End Function
Option Explicit
'These functions have been developed by Alan Forster on 27th September 2004.
'After years of desire he has actually written them!
'The functions use the same evaluation methods as the CountIf and SumIf functions
Public Function MinIf(rngEvaluate As Range, _
strCondition As String, _
Optional rngValues As Range = Nothing) As Variant
Dim varValue As Variant
Dim bolValueSet As Boolean
Dim intRow As Integer, _
intCol As Integer
If (rngValues Is Nothing) Then Set rngValues = rngEvaluate
bolValueSet = False
If Not RangesOK(rngEvaluate, rngValues) Then
'Return an error value
varValue = "Error in range selection"
Else
'If the ranges are not identically sized can not get this far!
For intRow = 1 To rngEvaluate.Rows.Count
For intCol = 1 To rngEvaluate.Columns.Count
If Application.CountIf(rngEvaluate(intRow, intCol), strCondition) = 1 Then
If bolValueSet Then
If varValue > rngValues(intRow, intCol) Then varValue = rngValues(intRow, intCol)
Else
bolValueSet = True
varValue = rngValues(intRow, intCol)
End If
End If
Next intCol
Next intRow
End If
MinIf = varValue
End Function
Public Function MaxIf(rngEvaluate As Range, _
strCondition As String, _
Optional rngValues As Range = Nothing) As Variant
Dim varValue As Variant
Dim bolValueSet As Boolean
Dim intRow As Integer, _
intCol As Integer
If (rngValues Is Nothing) Then Set rngValues = rngEvaluate
bolValueSet = False
If Not RangesOK(rngEvaluate, rngValues) Then
'Return an error value
varValue = "Error in range selection"
Else
'If the ranges are not identically sized can not get this far!
For intRow = 1 To rngEvaluate.Rows.Count
For intCol = 1 To rngEvaluate.Columns.Count
If Application.CountIf(rngEvaluate(intRow, intCol), strCondition) = 1 Then
If bolValueSet Then
If varValue < rngValues(intRow, intCol) Then varValue = rngValues(intRow, intCol)
Else
bolValueSet = True
varValue = rngValues(intRow, intCol)
End If
End If
Next intCol
Next intRow
End If
MaxIf = varValue
End Function
Private Function RangesOK(rng1 As Range, rng2 As Range) As Boolean
Dim bolAreas As Boolean, _
bolSize As Boolean
bolAreas = (rng1.Areas.Count = 1) Or (rng2.Areas.Count = 1)
bolSize = (rng1.Rows.Count = rng2.Rows.Count) And _
(rng1.Columns.Count = rng2.Columns.Count)
RangesOK = bolAreas And bolSize
End Function
Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel
Postado : 18/03/2012 4:38 pm