Trier simultanément plusieurs blocs de données
Dans cette première solution, les 4 colonnes de chaque plage sont triées séparément.
sub Tri1()
For i = 1 To 4 ' Quatre colonnes à trier (A à D)
Cells(1, i).Select
ActiveCell.End(xlDown).Select
While ActiveCell.Row < 65536
ActiveCell.Resize(ActiveCell.End(xlDown).Row - ActiveCell.Row +
1, 1).Select
Selection.Sort Key1:=Cells(1, i), Order1:=xlAscending,
Header:=xlGuess
ActiveCell.End(xlDown).Select
ActiveCell.End(xlDown).Select
Wend
Next i
Range("a1").Select
end sub Laurent Mortézai
Dans ces 3 autres procédures, les colonnes A à D sont triées ensemble sur le critère de la colonne A.
sub TrierParPlages() 'Frédéric Sigonneau
Dim i%
i = 1
Do While i < Range("A65536").End(xlUp).Row
If Not IsEmpty(Range("A" & i)) Then
Range("A" & i).CurrentRegion.Resize(, 4).Sort Range("A" & i) 'cols A:D
i = i + Range("A" & i).CurrentRegion.Rows.Count
Else: i = i + 1
End If
Loop
end subsub TriParPlages1()
Dim C As New Collection, i%
i = 1
Do While i < Range("A65536").End(xlUp).Row
If Not IsEmpty(Range("A" & i)) Then
C.Add Range("A" & i).CurrentRegion.Resize(, 4) 'cols A:D
i = i + Range("A" & i).CurrentRegion.Rows.Count
Else: i = i + 1
End If
Loop
For i = 1 To C.Count
C(i).Sort C(i).Range("A1")
Next
end subsub TrierSurPlusieursPlages() ' Denis Michon Dim MyRange As Range Set MyRange = ActiveSheet.UsedRange Dim Tbl() On Error Resume Next For A = 1 To MyRange.Rows.Count If Cells(A, 1) = "" Then B = B + 1 ReDim Preserve Tbl(B) Tbl(B) = Cells(A + 1, 1).Address Else If A = 1 Then B = B + 1 ReDim Preserve Tbl(B) Tbl(B) = Cells(A, 1).Address End If End If Next For A = 1 To B With Range(Tbl(A)).CurrentRegion .Sort Key1:=Range(Tbl(A)), order1:=xlAscending End With Next end sub
Auteurs : Laurent Mortézai, Denis Michon, Frédéric Sigonneau
Mots clefs associés à cette page : multiple, plage, trier, tri
- Vous devez vous identifier ou créer un compte pour écrire des commentaires
