VBA Sort table with multiple criteria

Опубликовано: 15 Октябрь 2024
на канале: Simplified Excellence
385
2

Sort a table with multiple criteria or columns

Code:
Sub sort_table_with_multiple_criterias()

Dim ws_sheet As Worksheet
Dim tbl As ListObject

'identify worksheet
Set ws_sheet = Worksheets(4)

'identify table
Set tbl = ws_sheet.ListObjects(1)

'sort by gender and name
With tbl.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("Table1[Gender]"), SortOn:=xlSortOnValues, Order:=xlAscending
.SortFields.Add Key:=Range("Table1[Name]"), SortOn:=xlSortOnValues, Order:=xlAscending
.Header = xlYes
.Apply
End With

End Sub

-------------------------------
NEED HELP?
-------------------------------
Leave a comment with your questions, issues or projetcs and I will try to answer with a video.

-------------------------------
THANK YOU
-------------------------------
For watching my videos,
Your shares
And your comments!