Skip to content

Instantly share code, notes, and snippets.

@DuongAQ
Last active Jun 6, 2019
Embed
What would you like to do?
Sub SapXep()
'Bien dong cuoi
Dim lr As Long
lr = Worksheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
'Dieu kien chi sap xep khi bang tinh co du lieu
If lr > 1 Then 'Dong tieu de la dong 1
'Xoa cac noi dung sap xep truoc do
ActiveWorkbook.Worksheets("Data").Sort.SortFields.Clear
'Sap xep
ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add2 Key:=Range("A2:A" & lr), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Data").Sort
.SetRange Range("A1:E" & lr)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment