Hi VBA Friends, I need your help again.
The below VBA loop help me to sort multiple columns for multiple tables in multiple sheets, and it works perfectly.
Now after these actions, for each table, I need to find the last row of all these tables and bring to the top row (first row after header) of the table (cut and paste). I tried few times and its not working.
Many thanks in advance!
VBA Code:
Public Sub Sort_Tables()
Dim sheetsTables As Variant
Dim i As Long
sheetsTables = Split("Jan22 tblMth01 Feb22 tblMth02 Mar22 tblMth03 Apr22 tblMth04 May22 tblMth05 Jun22 tblMth06 Jul22 tblMth07 Aug22 tblMth08 Sep22 tblMth09 Oct22 tblMth10 Nov22 tblMth11 Dec22 tblMth12")
For i = 0 To UBound(sheetsTables) Step 2
With ActiveWorkbook.Worksheets(sheetsTables(i)).ListObjects(sheetsTables(i + 1)).Sort
.SortFields.Clear
.SortFields.Add2 Key:=Range(sheetsTables(i + 1) & "[PSM]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add2 Key:=Range(sheetsTables(i + 1) & "[Type]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add2 Key:=Range(sheetsTables(i + 1) & "[Client]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add2 Key:=Range(sheetsTables(i + 1) & "[Event]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add2 Key:=Range(sheetsTables(i + 1) & "[Date End]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Next
End Sub
The below VBA loop help me to sort multiple columns for multiple tables in multiple sheets, and it works perfectly.
Now after these actions, for each table, I need to find the last row of all these tables and bring to the top row (first row after header) of the table (cut and paste). I tried few times and its not working.
Many thanks in advance!
VBA Code:
Public Sub Sort_Tables()
Dim sheetsTables As Variant
Dim i As Long
sheetsTables = Split("Jan22 tblMth01 Feb22 tblMth02 Mar22 tblMth03 Apr22 tblMth04 May22 tblMth05 Jun22 tblMth06 Jul22 tblMth07 Aug22 tblMth08 Sep22 tblMth09 Oct22 tblMth10 Nov22 tblMth11 Dec22 tblMth12")
For i = 0 To UBound(sheetsTables) Step 2
With ActiveWorkbook.Worksheets(sheetsTables(i)).ListObjects(sheetsTables(i + 1)).Sort
.SortFields.Clear
.SortFields.Add2 Key:=Range(sheetsTables(i + 1) & "[PSM]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add2 Key:=Range(sheetsTables(i + 1) & "[Type]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add2 Key:=Range(sheetsTables(i + 1) & "[Client]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add2 Key:=Range(sheetsTables(i + 1) & "[Event]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add2 Key:=Range(sheetsTables(i + 1) & "[Date End]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Next
End Sub