Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to auto sort date when date is entered or changed in Excel? 

In Excel, the Sort function can help you to sort date in ascending or descending order as you need. But it isn’t dynamic, if you have sorted the date and then add new date to it, you would need to sort it again. Are there any good and quick ways for you to auto sort the date when entering new date each time in a worksheet?

Auto sort date when date is entered or changed with formula

Auto sort date when date is entered or changed with VBA code


arrow blue right bubble Auto sort date when date is entered or changed with formula


For example, the original date in Column A, the following formula can help you to auto sort the date or any other text strings in a new helper column based on the column that you want to sort, please do as follows:

1. Enter this formula:

=INDEX($A$2:$A$15,MATCH(ROWS($A$2:A2),COUNTIF($A$2:$A$15,"<="&$A$2:$A$15),0)) into a blank cell beside your date column, C2, for example, and then press Ctrl + Shift + Enter keys together,  and you will get a number sequence, then drag the fill handle down to the cells that you want to use, see screenshot:

Note: In above formula: A2:A15 is your original date range that you want to auto sort.

doc autosort by date 1

2. Then format the numbers as date format by clicking Short Date from the General drop down list under the Home tab, see screenshot:

doc autosort by date 2

3. Then the sequence numbers have been converted to date format, and the original date has been sorted as well, see screenshot:

doc autosort by date 3

4. From now on, when you entering new date or change the date in column A, the date in column C will be sort in ascending order automatically, see screenshot:

doc autosort by date 4


arrow blue right bubble Auto sort date when date is entered or changed with VBA code

The following VBA code can help you to auto sort the date in the original column when you enter new date or change the date as you need.

1. Go the worksheet that you want to auto sort the date when you enter or change a date.

2. Right click the sheet tab, and select View Code from the context menu, in the popped out Microsoft Visual Basic for Applications window, please copy and paste the following code into the blank Module window, see screenshot:

VBA code: auto sort when date is entered or changed:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20160606
    On Error Resume Next
    If Application.Intersect(Target, Application.Columns(1)) Is Nothing Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    Range("A1").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
                                        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

doc autosort by date 6

Note: In the above code, the entered date will be auto sort in column A, you can change A1 and A2 to your own cells as you need.

3. From now on, when you enter date in column A, the date will be sorted ascending automatically.


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Ross · 1 months ago
    With the VBA code, I have copy and pasted the above but wish for the dates in column F to be the values by which the data is sorted. I've changed the range values to F2 and F3500 (the size of the spreadsheet where row 1 is titles), but it still sorts by the dates in column A. Can somebody help me please?
    • To post as a guest, your comment is unpublished.
      skyyang · 25 days ago
      Hello, Ross,
      When applying the code to column F, you should change some references to your need as below code:
      Private Sub Worksheet_Change(ByVal Target As Range)
      'Updateby Extendoffice 20160606
      On Error Resume Next
      If Application.Intersect(Target, Application.Columns(6)) Is Nothing Then Exit Sub
      If Target.Count > 1 Then Exit Sub
      Range("F1").Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlYes, _
      OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
      End Sub

      Please try, hope it can help you!
  • To post as a guest, your comment is unpublished.
    Hector · 2 months ago
    Is there a particular formula to keep the cells following the sorted date? It would be nice to organize by date but keep the entire row of information. Any help would be much appreciated.
  • To post as a guest, your comment is unpublished.
    Robert Smith · 6 months ago
    I mad a checkbook register and it works but I want to figure out how to make my entry’s to go into date order. Any help would be appreciated. I’m still learning excel.
  • To post as a guest, your comment is unpublished.
    KC · 11 months ago
    In addition to the duplicate dates, is there also a way to include multiple columns of data when it sorts? I need it to include multiple columns and sort them all together with the expiration dates.
  • To post as a guest, your comment is unpublished.
    Bo · 11 months ago
    how can I do this same sorting calculation but from newest date to oldest? Currently it is Oldest to Newest. Flipping the < sign isn't enough and beyond that I don't have a strong enough understanding of what it is doing. Also I think what may be happening is excel automatically works top to bottom causing difficulties.
    • To post as a guest, your comment is unpublished.
      skyyang · 11 months ago
      Hello, Bo,

      To auto sort the date from newest to oldest, you just need to change the <= to >= in the above formula as follows:
      =INDEX($A$2:$A$15,MATCH(ROWS($A$2:A2),COUNTIF($A$2:$A$15,">="&$A$2:$A$15),0))
      After inserting this formula, please remember to press Ctrl + Shift + Enter keys together to get the correct result.
      Please try it.