Hi,
As usual I don't know where to start. I'm looking for VBA code to sort different tables (table name in below), but they are in different work sheets. I'd like to sort them in multiple columns.
Table_name Sheet_Name
tblMth01 Jan22
tblMth02 Feb22
tblMth03 Mar22
tblMth04 Apr22
tblMth05 May22
tblMth06 Jun22
tblMth07 Jul22
tblMth08 Aug22
tblMth09 Sep22
tblMth10 Oct22
tblMth11 Nov22
tblMth12 Dec22
Sorting criteria:
[PSM], then [Type], then [Client], then [Event], then [Date End].
Current code I've got and its now working as I wanted are:
Sub Sort_tblMth01()
'
Range("tblMth01").Select
Range("T19").Activate
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Add2 Key:=Range("tblMth01[PSM]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Add2 Key:=Range("tblMth01[Type]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Add2 Key:=Range("tblMth01[Client]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Add2 Key:=Range("tblMth01[Event]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Add2 Key:=Range("tblMth01[Date End]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Appreciate in advance!
As usual I don't know where to start. I'm looking for VBA code to sort different tables (table name in below), but they are in different work sheets. I'd like to sort them in multiple columns.
Table_name Sheet_Name
tblMth01 Jan22
tblMth02 Feb22
tblMth03 Mar22
tblMth04 Apr22
tblMth05 May22
tblMth06 Jun22
tblMth07 Jul22
tblMth08 Aug22
tblMth09 Sep22
tblMth10 Oct22
tblMth11 Nov22
tblMth12 Dec22
Sorting criteria:
[PSM], then [Type], then [Client], then [Event], then [Date End].
Current code I've got and its now working as I wanted are:
Sub Sort_tblMth01()
'
Range("tblMth01").Select
Range("T19").Activate
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Add2 Key:=Range("tblMth01[PSM]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Add2 Key:=Range("tblMth01[Type]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Add2 Key:=Range("tblMth01[Client]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Add2 Key:=Range("tblMth01[Event]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort.SortFields. _
Add2 Key:=Range("tblMth01[Date End]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("oJan22").ListObjects("tblMth01").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Appreciate in advance!