
Option Explicit
Function max_if(r As Range, crit As Integer) As Long
Dim cell As Range, rng As Range
For Each cell In r
If cell < crit Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next
max_if = Application.Max(rng)
End Function |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Function max_se(ByVal rng As Range, ByVal sCrit As String) As Long
max_se = Evaluate("=MAX(INDEX((" & rng.Address & sCrit & ")*" & rng.Address & ",))")
End Function
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Function max_se2(ByVal rng As Range, ByVal sCrit As String) As Long
With Application
max_se2 = .Max(.Evaluate("Index((" & rng.Address & sCrit & ")*" & rng.Address & ",)"))
End With
End Function
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Function max_if2(r As Range, sCrit As String) As Long
Dim cell As Range, rng As Range
For Each cell In r
If Evaluate(cell.Address & sCrit) Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next
max_if2 = Application.Max(rng)
End Function |
Prototipo:
function m(rng as range, operator as string, value as long)
for each cell in rng
select case operator
case "<": if cell < value then set r = Union (r, rng)
case ">": if cell > value ...
case "<=": ....
ecc.
end select
next
m = Max(r)
end function
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Function Max_SeOP(ByVal rng As Range, ByVal sOp As String, nVal As Double) As Double
Dim vVal As Variant
Dim aVal As Variant
Dim j As Long
aVal = Application.Transpose(rng)
For j = LBound(aVal) To UBound(aVal)
vVal = aVal(j)
aVal(j) = (sOp = "<") * (vVal < nVal) * vVal + (sOp = "<=") * (vVal <= nVal) * vVal + (sOp = ">") * (vVal > nVal) * vVal + _
(sOp = ">=") * (vVal >= nVal) * vVal + (sOp = "<>") * (vVal <> nVal) * vVal
Next
Max_SeOP = Application.Max(aVal)
End Function
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
