Forum Discussion

auburnshell's avatar
auburnshell
Copper Contributor
Jan 25, 2018

custom sort

Can you set a custom sort to run at save so every time you add new data it automatically sorts?  I have a spreadsheet of projects and when a completion date is put in column j, I want that project to move to the top sorted by date.  I have a custom sort set up that works but I want to know if it can run automatically.

1 Reply

  • Haytham Amairah's avatar
    Haytham Amairah
    Silver Contributor

    Hi,

     

    Try the solution in the attached file, it's powered by this code:

    'Reference: https://www.extendoffice.com/documents/excel/2592-excel-auto-sort-by-value.html
    'Updated by Haytham Amairah 1/25/2018
    Private Sub Worksheet_Change(ByVal Target As Range)
        On Error Resume Next
        If Not Intersect(Target, Range("A:B")) Is Nothing Then
            Range("B1").Sort Key1:=Range("B2"), _
            Order1:=xlAscending, Header:=xlYes, _
            OrderCustom:=1, MatchCase:=False, _
            Orientation:=xlTopToBottom
        End If
        On Error GoTo 0
    End Sub

Resources