Previously i gt the below MACRO from a helper user here. But i need some help to other sorting.
Can i sort as show below? But do take note on the one in red.
"S/N" is in cell A1:
Before:
Sheet4 (2)[TABLE="class: cms_table_html-maker-worksheet"]
<tbody>[TR]
[TH="align: center"][/TH]
[TH="align: center"]A[/TH]
[TH="align: center"]B[/TH]
[TH="align: center"]C[/TH]
[TH="align: center"]D[/TH]
[TH="align: center"]E[/TH]
[TH="align: center"]F[/TH]
[TH="align: center"]G[/TH]
[TH="align: center"]H[/TH]
[/TR]
[TR]
[TH="align: center"]1[/TH]
[TD]S/N[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH="align: center"]2[/TH]
[TD="align: right"]1111[/TD]
[TD="align: right"]8846[/TD]
[TD="align: right"]62[/TD]
[TD="align: right"]7688e[/TD]
[TD="align: right"]7688[/TD]
[TD="align: right"]2376[/TD]
[TD="align: right"]6100[/TD]
[TD="align: right"]6100a[/TD]
[/TR]
[TR]
[TH="align: center"]3[/TH]
[TD="align: right"]1112[/TD]
[TD="align: right"]3086[/TD]
[TD][/TD]
[TD="align: right"]3086a[/TD]
[TD][/TD]
[TD="align: right"]ABC[/TD]
[TD="align: right"]8991[/TD]
[TD][/TD]
[/TR]
[TR]
[TH="align: center"][/TH]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]
After:
Sheet4 (2)
[TABLE="class: cms_table_html-maker-worksheet"]
<tbody>[TR]
[TH="align: center"][/TH]
[TH="align: center"]A[/TH]
[TH="align: center"]B[/TH]
[TH="align: center"]C[/TH]
[TH="align: center"]D[/TH]
[TH="align: center"]E[/TH]
[TH="align: center"]F[/TH]
[TH="align: center"]G[/TH]
[TH="align: center"]H[/TH]
[/TR]
[TR]
[TH="align: center"]1[/TH]
[TD]S/M[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH="align: center"]2[/TH]
[TD="align: right"]1111[/TD]
[TD="align: right"]62[/TD]
[TD="align: right"]2376[/TD]
[TD="align: right"]6100[/TD]
[TD="align: right"]6100a[/TD]
[TD="align: right"]7688[/TD]
[TD="align: right"]7688e[/TD]
[TD="align: right"]8846[/TD]
[/TR]
[TR]
[TH="align: center"]3[/TH]
[TD="align: right"]1112[/TD]
[TD="align: right"]ABC[/TD]
[TD="align: right"]3086[/TD]
[TD="align: right"]3086a[/TD]
[TD="align: right"]8991[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH="align: center"][/TH]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Can i sort as show below? But do take note on the one in red.
"S/N" is in cell A1:
Before:
Sheet4 (2)[TABLE="class: cms_table_html-maker-worksheet"]
<tbody>[TR]
[TH="align: center"][/TH]
[TH="align: center"]A[/TH]
[TH="align: center"]B[/TH]
[TH="align: center"]C[/TH]
[TH="align: center"]D[/TH]
[TH="align: center"]E[/TH]
[TH="align: center"]F[/TH]
[TH="align: center"]G[/TH]
[TH="align: center"]H[/TH]
[/TR]
[TR]
[TH="align: center"]1[/TH]
[TD]S/N[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH="align: center"]2[/TH]
[TD="align: right"]1111[/TD]
[TD="align: right"]8846[/TD]
[TD="align: right"]62[/TD]
[TD="align: right"]7688e[/TD]
[TD="align: right"]7688[/TD]
[TD="align: right"]2376[/TD]
[TD="align: right"]6100[/TD]
[TD="align: right"]6100a[/TD]
[/TR]
[TR]
[TH="align: center"]3[/TH]
[TD="align: right"]1112[/TD]
[TD="align: right"]3086[/TD]
[TD][/TD]
[TD="align: right"]3086a[/TD]
[TD][/TD]
[TD="align: right"]ABC[/TD]
[TD="align: right"]8991[/TD]
[TD][/TD]
[/TR]
[TR]
[TH="align: center"][/TH]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]
After:
Sheet4 (2)
[TABLE="class: cms_table_html-maker-worksheet"]
<tbody>[TR]
[TH="align: center"][/TH]
[TH="align: center"]A[/TH]
[TH="align: center"]B[/TH]
[TH="align: center"]C[/TH]
[TH="align: center"]D[/TH]
[TH="align: center"]E[/TH]
[TH="align: center"]F[/TH]
[TH="align: center"]G[/TH]
[TH="align: center"]H[/TH]
[/TR]
[TR]
[TH="align: center"]1[/TH]
[TD]S/M[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH="align: center"]2[/TH]
[TD="align: right"]1111[/TD]
[TD="align: right"]62[/TD]
[TD="align: right"]2376[/TD]
[TD="align: right"]6100[/TD]
[TD="align: right"]6100a[/TD]
[TD="align: right"]7688[/TD]
[TD="align: right"]7688e[/TD]
[TD="align: right"]8846[/TD]
[/TR]
[TR]
[TH="align: center"]3[/TH]
[TD="align: right"]1112[/TD]
[TD="align: right"]ABC[/TD]
[TD="align: right"]3086[/TD]
[TD="align: right"]3086a[/TD]
[TD="align: right"]8991[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TH="align: center"][/TH]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Code:
Option Explicit
Sub example()
Dim WKS As Worksheet
Dim rng2Sort As Range
Dim Index As Long
Dim CalcMode As XlCalculation
CalcMode = Application.Calculation
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Set WKS = ActiveSheet ' or by sheet's tab name ThisWorkbook.Worksheets("Sheet4") or just use Codename
Set rng2Sort = WKS.Range("A1").CurrentRegion
Set rng2Sort = rng2Sort.Offset(1, 1).Resize(rng2Sort.Rows.Count - 1, rng2Sort.Columns.Count - 1)
For Index = rng2Sort.Rows.Count To 1 Step -1
With rng2Sort.Rows(Index)
.Sort Key1:=.Cells(1), Order1:=xlAscending, Orientation:=xlSortRows
End With
Next
Application.Calculation = CalcMode
Application.ScreenUpdating = True
End Sub