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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
Sub Test()
TriLatéral InputBox("Quel mot cherché ?", "Tri", "")
End Sub
Sub TriLatéral(Texte As String)
Dim Plage As Range
Dim Cel As Range
Dim Tbl() As Integer
Dim Adr As String
Dim I As Integer
Dim Max As Integer
'sur la feuille active
With ActiveSheet
Set Plage = .Range(.Cells(1, 1), .Cells(1, .Columns.Count).End(xlUp))
Set Cel = Plage.Find(Texte, .Cells(1, .Columns.Count), xlValues, xlPart)
End With
'si trouvé,
If Not Cel Is Nothing Then
Adr = Cel.Address
'boucle et stocke les n° de colonnes dans un tableau
Do
I = I + 1
ReDim Preserve Tbl(1 To I)
Tbl(I) = Cel.Column
Set Cel = Plage.FindNext(Cel)
Loop While Adr <> Cel.Address
'récup du nombre de colonne correspondantes
Max = UBound(Tbl)
'insère le nombre de colonnes en A
For I = 1 To Max
Columns(1).Insert xlToRight
Next I
'déplace les colonnes concernées
For I = 1 To UBound(Tbl)
Columns(Tbl(I) + Max).Cut Columns(I)
Columns(Tbl(I) + Max).Delete xlToLeft
Max = Max - 1
Next I
Else
MsgBox "Mot non trouvé !"
End If
End Sub |