macro filter column for most recent date

F

flymo

Helo,
I have a macro running to filter a series of values and works fine so
far. However, I need to filter a column of dates and only need to
select records with the most recent date (I can't make the field =
NOW() to get current date as the records may include today but also
may be a few days old.

Cells.Select
Selection.AutoFilter
Selection.AutoFilter Field:=4, Criteria1:="HHP"
Selection.AutoFilter Field:=3, Criteria1:="Open"
Selection.AutoFilter Field:=2, Criteria1:="2007/06/14 21:00" '
this is the most current right now - so may change day to day
Range("A171:AV171").Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Selection.Columns.AutoFit


Many thanks
John
 
B

Bernie Deitrick

John,

Use this in place of your field 2 code:

Selection.AutoFilter Field:=2, Criteria1:="1", Operator:=xlTop10Items

HTH,
Bernie
MS Excel MVP
 
T

Tom Ogilvy

Cells.Select
Dim dt as Date
' the next line assumes the date column is in the column to the right of
the upper
' left corner of the selection. Adjust to suit.
dt = clng(Application.Max(selection(1).offset(0,1).EntireColumn))
Selection.AutoFilter
Selection.AutoFilter Field:=4, Criteria1:="HHP"
Selection.AutoFilter Field:=3, Criteria1:="Open"
Selection.AutoFilter Field:=2, Criteria1:=">=" & format(dt,"yyyy/mm/dd")
this is the most current right now - so may change day to day
Range("A171:AV171").Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Selection.Columns.AutoFit
 
F

flymo

John,

Use this in place of your field 2 code:

Selection.AutoFilter Field:=2, Criteria1:="1", Operator:=xlTop10Items

HTH,
Bernie
MS Excel MVP
Bernie,
Worked like a charm.
Many Thanks

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top