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.


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
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 · 7 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 · 7 months 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 · 8 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 · 1 years 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 · 1 years 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 · 1 years 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 · 1 years 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.
  • To post as a guest, your comment is unpublished.
    Ryan · 2 years ago
    What if there is a duplicate date in the list? And I want both numbers to show up.
    • To post as a guest, your comment is unpublished.
      skyyang · 2 years ago
      Hello, Ryan,

      To sort the date with duplicate ones, you should apply the following formula:

      =IFERROR(INDEX($A$2:$A$11,MATCH(ROWS($A$2:A2),COUNTIF($A$2:$A$11,"<="&$A$2:$A$11),0)),IF(ROWS($A$2:A2)<ROWS($A$2:$A$11),B3,""))

      Please remember to press Shift + Ctrl + Enter keys together.

      Hope it can help you, thank you!
  • To post as a guest, your comment is unpublished.
    UrLoser · 2 years ago
    U forgot to mention the formula is array and you need to ctrl+Shift+ enter. Luckily you had a screenshot or your page would be a waste of cyberspace