and perhaps better..
User Defined function (UDF) called MaxFlow (code is at the end of this
post)
Syntax:
=MaxFlow(A5:B41,1,2,"8/25/2005","9/12/2005")
or
=MaxFlow(A5:B41,1,2,L3,L4)
Where:
A5:B41 is the range which contain the dates and values but NOT the
column headers of same.
1 is the column number of the above range containing the dates (their
sort order is irrelevant, in fact they don't need to be sorted).
2 is the column number of the above range containing the values from
which the max must be obtained.
"8/25/2005" is the earlier date in the format that excel can recognise
as a date. (This can also be a reference to a cell containing a date.)
"9/12/2005" is the later date in the format that excel can recognise
as a date. (This can also be a reference to a cell containing a date.)
This UDF has a cleaner way to enter the formula on the sheet but it
isn't as efficient as the previous array formula (which can,
incidentally be simplified further:
=MAX(((A5:A41>=DATEVALUE("August 15,
2005"))*1)*((A5:A41<=DATEVALUE("August 24, 2005"))*1)*(B5:B41))
also entered as an array formula. I cocked up in the LARGE example in
the last post slightly by having the dates the wrong way round; the
earlier date should always be the first.
If I knew a one line way to multiply arrays in vba, it could be as
efficient.
Anyway that code:
Function MaxFlow(myData As Range, DatesColumn As Integer, _
ValuesColumn As Integer, FirstDate As String, SecondDate As String)
Application.Volatile
myarray = myData
MaxFlow = -1E+24
NoOfRows = myData.Rows.Count
For i = 1 To NoOfRows
If myarray(i, DatesColumn) >= DateValue(FirstDate) _
And myarray(i, DatesColumn) <= DateValue(SecondDate) Then
If MaxFlow < myarray(i, ValuesColumn) Then _
MaxFlow = myarray(i, ValuesColumn)
End If
Next i
End Function
If you don't know what to do with this code then go to and follow
instructions at:
office.microsoft.com/.../HA010548461033.aspx
and when you reach point 3 in it, instead of where it says 'type the
code for your function', paste the block of code into it then carry on
with the rest of the instructions.