I need to combine a UDF (below) with a set of IF functions.
Function MaxN(n&, r As Range)
Dim i&, j&, m#, t#, v
v = r.Cells.Value2
For i = 1 To UBound(v)
If UBound(v) - i + 1 >= n Then
t = 0
For j = i To i + n - 1
t = t + v(j, 1)
Next
If t > m Then m = t
Else
Exit For
End If
Next
MaxN = m
End Function
I'm trying to use this UDF (which finds the max value of 5 consecutive cells in a range) in combination with IF functions.
Eg: IF(A1=D1) and IF(B1=E1) then apply the UDf, otherwise leave blank (or = 0)
Appreciate the help!
Function MaxN(n&, r As Range)
Dim i&, j&, m#, t#, v
v = r.Cells.Value2
For i = 1 To UBound(v)
If UBound(v) - i + 1 >= n Then
t = 0
For j = i To i + n - 1
t = t + v(j, 1)
Next
If t > m Then m = t
Else
Exit For
End If
Next
MaxN = m
End Function
I'm trying to use this UDF (which finds the max value of 5 consecutive cells in a range) in combination with IF functions.
Eg: IF(A1=D1) and IF(B1=E1) then apply the UDf, otherwise leave blank (or = 0)
Appreciate the help!