Forum Discussion

Stevy_M's avatar
Stevy_M
Copper Contributor
Jun 17, 2021
Solved

Auto sort in Excel based on multiple columns

Hello,   I've seen multiple solutions for how to use VBA codes to auto-sort an excel sheet when there's a change in data. All these solutions, however, are based on sorting by values of a SINGLE co...
  • Stevy_M's avatar
    Jun 17, 2021
    Here's the VBA code I could put together that works:

    Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Not Intersect(Target, Range("B3:C500")) Is Nothing Then
    Columns("A:F").Sort Key1:=Range("B4"), Key2:=Range("C4"), _
    Order1:=xlDescending, Order2:=xlDescending, Header:=xlYes, _
    OrderCustom:=1, MatchCase:=False, _
    Orientation:=xlTopToBottom
    End If
    End Sub

Resources