Sub TRI()
Dim Dlig As Integer ' variable pour trouver la dernière ligne
Dlig = Cells(Rows.Count, "A").End(xlUp).Row ' trouver la dernière ligne de la colonne A
Range("A1:I" & Dlig).Select ' sélectionne la plage
ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Clear ' vide la dernière recherche
' effectue la recherche
ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Add Key:=Range("G2:G2" & Dlig) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Feuil1").Sort
.SetRange Range("A1:I" & Dlig)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Cells(15, "K").Select ' sélectionne K15 pour désélectionner la plage de la recherche.
Call AjouterLignes ' appelle une autre macro
End Sub
Sub AjouterLignes()
Dim Dlig As Integer ' variable pour trouver la dernière ligne
Dim X As Integer
Dlig = Cells(Rows.Count, "A").End(xlUp).Row ' trouver la dernière ligne de la colonne A
For X = Dlig To 3 Step -1 ' boucle de la dernière ligne en remontant jusqu'à la ligne 3
' si la valeur de Gx est différente de Gx-1 (ligne au dessus)
If Cells(X, "G").Value <> Cells(X - 1, "G").Value Then
' Si vrai, sélectionne Ax:Ix et insère une ligne
Range("A" & X & ":i" & X).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End If
Next X ' boucle sur la ligne précédente (puisqu'on remonte)
End Sub