View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Sorting DateTime Values in Array

Probably be quicker to do

Dim maxDate As Date
Dim dt as Date
For i = 1 To 10
dt = arr(i)
If maxDate < dt Then maxDate = dt
Next
msgbox "Max date is " & format(maxDate, "mm/dd/yyyy hh:mm")

--
Regards,
Tom Ogilvy


"Kevin" wrote:

I have an array of dates/times in the format "mm/dd/yy hh:mm". The
array is one-dimensional.

I want to pick the max/min, but it won't work. My code:

msgbox WorksheetFunction.Max(arrResults())

I am getting "0" when I run this code now.

I read he http://tinyurl.com/q6jm6 this is a misbehavior on Excel's
part and I'll have to find another way. The problem with the proposed
solution is that it uses dateserial function. I also need the time and
I don't think the dateserial function keeps the time (am I wrong?).

So here's my new thinking:

Couldn't I just sort the array and pick the first or last element as min
or max?

Anyone have a good bubble sort routine for date/time combinations OR a
friendly pointer on how to write one (i.e., what functions to use that
aren't broken/buggy). There seems to be few topics on this subject in
the newsgroups and I desperately need to get something working.

Thank you for taking the time to read my post.

-Kevin