SOLVED

Auto sort in Excel based on multiple columns

New Contributor

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 column.

Looking at my attached sample, is there any way to have the data updated automatically by sorting values by looking at Column B first, and then column C? (descending would be preferred).

 

Many thanks in advance!

 

1 Reply
best response confirmed by Stevy_M (New Contributor)
Solution
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