#1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default sort dates

I have a list of 100 dates (some are duplicate) - how do I find the 5 most
recent unique dates?
Many thanks,
Dan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default sort dates

Dan,

For example, in cell C1:

=MAX(A1:A100)

In cell C2, array enter (enter using Ctrl-Shift-Enter)
=MAX(($A$1:$A$1000<C1)*$A$1:$A$1000)

and then copy C2 to C3:C5.

HTH,
Bernie
MS Excel MVP


"Dan" wrote in message
...
I have a list of 100 dates (some are duplicate) - how do I find the 5 most
recent unique dates?
Many thanks,
Dan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default sort dates

Dan,

I just realized that you are in programming....

Try the code below.

HTH,
Bernie
MS Excel MVP


Sub Find5LatestDates()
Dim Latest(1 To 5) As Date
Dim myC As Range
Dim i As Integer
Dim j As Integer

For Each myC In Range("A1:A100")
For i = 1 To 5
If myC.Value = Latest(i) Then GoTo NextDate
Next i
For i = 1 To 5
If myC.Value Latest(i) Then
For j = 4 To i Step -1
Latest(j + 1) = Latest(j)
Next j
Latest(i) = myC.Value
GoTo NextDate
End If
Next i
NextDate:
Next myC

For i = 1 To 5
MsgBox Format(Latest(i), "mm/dd/yyyy")
Next i

End Sub


"Dan" wrote in message
...
I have a list of 100 dates (some are duplicate) - how do I find the 5 most
recent unique dates?
Many thanks,
Dan



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 806
Default sort dates

Hello,

I suggest to steal code:

Sub Pfreq_Sample()
Range("B1:B5").FormulaArray = GSort(Pfreq(Range("A1:A30")), "D")
End Sub

Pfreq you can find he
http://www.sulprobil.com/html/pfreq.html

GSort you can get he
http://www.sulprobil.com/html/sort_vba.html

Regards,
Bernd
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort Dates pete5440 Excel Worksheet Functions 8 January 17th 09 04:54 PM
sort dates Pammy Excel Discussion (Misc queries) 2 April 14th 08 09:55 PM
sort function for dates does not sort properly in Office 2007 Exc. Rosalie Excel Worksheet Functions 1 November 22nd 07 10:25 PM
how do I sort a column of random dates into Consecutive dates Rob Gibson Excel Worksheet Functions 2 June 12th 07 05:10 AM
sort dates Debgala Excel Worksheet Functions 5 August 10th 05 12:05 AM


All times are GMT +1. The time now is 02:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"