Thread: Latest date
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
AA2e72E AA2e72E is offline
external usenet poster
 
Posts: 400
Default Latest date

The first attempt is lacking! (Did not consider Pol No.) Try this:

Sub LatestDate()
Set adors = CreateObject("ADODB.RecordSet")
Cnn = "Provider=MSDASQL;Driver={Microsoft Excel Driver
(*.xls)};DBQ=c:\latest.xls;"
Sql = "SELECT [Pol No],max(Date)as [Latest Date] FROM [SHEET1$] GROUP BY
[Pol No]; "
adors.Open Sql, Cnn
While Not adors.EOF
Debug.Print adors("Pol No").Value & adors("Latest Date").Value
adors.Movenext
Wend
End Sub

1. If you are using a workbook that is open, specify DBQ accordingly.
2. If your data is in a range, name that ranhe and specify it instead of
Sheet1$: no $ for range names
3. You can capture the calues in the Debug.print line in variables.

"AA2e72E" wrote:

In a cell formatted as dd/mm/yyyy, type this formula:

=LARGE("A1:A4",1) ' Assumes your dates are in A1:A4

"ChristinaC" wrote:

Can someone help me with this one. I have a spreadsheet with a list of
Purchase orders that have more than one line. Eg

Po No Line Date
no
po12345 1 18/02/2004
po12345 2 05/04/2005
po12345 3 16/02/2003
po12345 4 06/02/2004
po12346 1 09/02/2005 etc.....

Can someone show me what code I need to use to find the latest date in the
third column against each po number. Hope this makes sense.