PDA

View Full Version : sort by upcoming date 60 days from today



wilg
06-12-2012, 09:45 AM
Hi there. I have a spreadsheet with information on it from column A:V, 400 +/- rows

In column N has a date that a goal is due by that each row has different dates of the year non sorted.

There is approx 400 rows.

I need to sort rows selecting column N so that it descends [U]60 days from today's current day.

eg if one row has Dec 3rd and another row has April 2nd it would be sorted...

Dec 3
Apr 2
etc...

If I use a regular sort it would decent chronologically

Apr 2
Dec 3

I need to sort by what is coming up 60 days from "Today()"

All help is appreciated.

Teeroy
07-07-2012, 12:00 AM
Hi Wilg,

The following is very basic and assumes your data starts at A1 (with header row) but should work for you. It filters out data beyond 60 days from now then sorts (descending) the data left.

Sub FilterAndSort()
Dim lLatedate As Long

ActiveSheet.AutoFilterMode = False
lLatedate = DateValue(Date + 60)

With ActiveSheet.UsedRange
.Sort Key1:=Range("N1"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
.AutoFilter Field:=14, Criteria1:="<=" & lLatedate

End With
End Sub