How to auto sort by date

  • Thread starter Thread starter Juco
  • Start date Start date
J

Juco

I have several columns in worksheet, date,name post code etc. I would like
to sort the rows (within these columns) using the date as the trigger, can
this be easily done and can I do it automatically, that is ...if I enter a
new date it will automatically sort the rows into chronological order.

thanks
 
Hi
you'll need VBA for doing this kind of automation. One way would be
adding code to the worksheet_activateevent of your worksheet(so
autosort each time you enter the sheet). e.g. something like the
following:

Private Sub Worksheet_Activate()

Dim LastRow As Long



On Error GoTo errhandler

Application.EnableEvents = False

With Me

LastRow = .Cells(Rows.Count, 1).End(xlUp).Row

.Rows("1:" & LastRow).Sort Key1:=Range("A2"),
Order1:=xlAscending, _

Key2:=Range("B2"), Order2:=xlDescending, _

Key3:=Range("C2"), Order3:=xlAscending, _

Header:=xlYes, Orientation:=xlTopToBottom, _

OrderCustom:=1

End With



errhandler:

Application.EnableEvents = True



End Sub
 

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


Back
Top