Ameliorer trie de a-z
Bonjour,
j'utilise cette procédure depuis pas mal de temps, je la trouve désuète mais je n'arrive pas à l'améliorer car je l'avais créer avec l'outil 'record macro' d'excel.
Je vous remercie par avance pour votre aide
Sub trier_AZ()
Dim xrow As Integer
Dim xcolumn As Integer
Dim i As Integer
On Error GoTo ErrorHandler
If Sheets("data2").Range("A30") = 1 Then
xcolumn = ActiveCell.Column
xrow = ActiveCell.Row
Range("A4").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A4") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A4:V1048576")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
SendKeys "{ESC}"
Cells(xrow, xcolumn).Select
Else
Application.ScreenUpdating = False
xcolumn = ActiveCell.Column
xrow = ActiveCell.Row
Range("A4").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A4") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A4:V1048576")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
SendKeys "{ESC}"
Cells(xrow, xcolumn).Select
Application.ScreenUpdating = True
End If
Exit Sub
ErrorHandler:
MsgBox Err.Number & vbLf & Err.Description
End Sub
Salut,
J'ai trouvé ce petit code (ici), si ça peut t'être utile
A adapter à ton besoin
Sub Trier()
Dim derlg As Integer
derlg = ActiveSheet.Range("A65536").End(xlUp).Row
Range("A1:A" & derlg).Sort Key1:=Range("A1")
End Sub
top, merci!!!!!!!!!!!!!!!!!!!!!!!!!!!