Forum Discussion
Stevy_M
Jun 17, 2021Copper Contributor
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...
- Jun 17, 2021Here'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
Stevy_M
Jun 17, 2021Copper Contributor
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
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