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 37 38 39 40 41 42
| Private Sub CommandButton1_Click()
Dim nb_exch%, tb%(), i%
'nb echantillons
nb_exch = Range(Cells(7, 5), Cells(7, 5).End(xlToRight)).Count
'nettoyage
With Range(Cells(86, 1), Cells(Rows.Count, Columns.Count))
.Borders.LineStyle = xlNone
.ClearContents
End With
'transposition tableau
Range(Cells(71, 3), Cells(74, 3).End(xlToRight)).Copy
Cells(86, 3).PasteSpecial Paste:=xlPasteValues, Transpose:=True
'tri 1ère colonne
Range(Cells(88, 3), Cells(87 + nb_exch, 6).End(xlDown)).Sort Key1:=Cells(88, 3), _
Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
'repérage des doublons (triplets...) selon 1ère colonne
ReDim tb(1 To nb_exch): tb(1) = 1
For i = 2 To nb_exch
If Cells(87 + i, 3) <> Cells(86 + i, 3) Then
tb(i) = 1
Else
tb(i) = tb(i - 1) + 1
tb(i - 1) = 1
End If
Next i
'tris partiels supplémentaires éventuels des doublons (triplets...) selon 2ème colonne
For i = 2 To nb_exch
If tb(i) > 1 Then
Range(Cells(88 + i - tb(i), 3), Cells(87 + i, 6)).Sort Key1:=Cells(88 + i - tb(i), 4), _
Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End If
Next i
'format
With Range(Cells(86, 3), Cells(87 + nb_exch, 6)).Borders
.LineStyle = xlContinuous
.Weight = xlThin
End With
End Sub |
Partager