1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Option Explicit
Public Sub Test()
Dim ws As Worksheet
Set ws = Worksheets("Feuil1")
Dim rg As Range
Set rg = ws.Range(ws.Columns(1), ws.Columns(20))
Dim listColonne(4) As Integer
listColonne(0) = 1
listColonne(1) = 10
listColonne(2) = 7
listColonne(3) = 16
listColonne(4) = 19
TrierListeColonne rg, listColonne, True
End Sub
Public Sub TrierListeColonne(ByRef zoneTriee As Range, ByRef listColonne() As Integer _
, ByVal hasHeaders As Boolean)
Dim i As Integer
For i = 0 To UBound(listColonne)
TrierColonne listColonne(i), zoneTriee, hasHeaders
Next i
End Sub
Private Sub TrierColonne(ByVal numCol As Integer, ByRef rgCols As Range, ByVal hasHeaders As Boolean)
If hasHeaders Then
rgCols.Sort key1:=rgCols.Cells(2, numCol), order1:=xlAscending, header:=xlYes _
, MatchCase:=False, Orientation:=xlTopToBottom
Else
rgCols.Sort key1:=rgCols.Cells(1, numCol), order1:=xlAscending, header:=xlNo _
, MatchCase:=False, Orientation:=xlTopToBottom
End If
End Sub |
Partager