Use VBA in Excel to auto sort rows 5 to 100 based on two columns
00:34 17 May 2026

I'm a newbie, so I may need things dumbed down. I have a dataset with 4 rows of headers, so the data start on row 5. There are data in columns A through AU. I have a "totals" row static on row 101. I would like to create a VBA macro to automatically sort the data whenever a new entry is added. The first sort key would be column A and the second sort key would be column B. I have tried the following, and it works beautifully, except that it includes the headers in rows 2-4, as well as the totals in row 101 when sorting. For example, one of the headers in column A is "Day of the Week," and it moves that header between entries starting with C or E. What am I doing wrong? Thanks in advance.

Private Sub Worksheet_Change(ByVal Target As Range)
  
    If Not Intersect(Target, Range("A1:AU100")) Is Nothing Then
        On Error Resume Next
        Application.EnableEvents = False
        
Range("A5:AU100").Sort key1:=Range("A4"), order1:=xlAscending, _
                        Key2:=Range("B4"), Order2:=xlAscending, _
                    Header:=xlYes
            
        Application.EnableEvents = True
        On Error GoTo 0
    End If
End Sub
excel vba sorting