Sub Macro()
Dim Tableau, i As Long, x As Long, Prec As String
'** tri de la base par table puis par nom;
' adapter nom de feuille, plage et colonne de tri
With Worksheets("Feuil1") ' feuille contenant la base
.Range("I2:K" & .Range("I" & Rows.Count).End(xlUp).Row).Sort Key1:=.Range("K3"), _
Order1:=xlAscending, Key2:=.Range("J3") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
End With
' ** fin tri
With Worksheets("Feuil1") ' feuille contenant le tableau à renseigner
Prec = ""
Tableau = .Range("I3:K" & .Range("I" & Rows.Count).End(xlUp).Row)
For i = LBound(Tableau) To UBound(Tableau)
If Tableau(i, 3) <> "" Then
If Tableau(i, 3) <> Prec Then
Prec = Tableau(i, 3)
x = 2 + 6 * (Tableau(i, 3) - 1)
MsgBox x
End If
x = x + 1
.Cells(x, 3) = Tableau(i, 1)
.Cells(x, 4) = Tableau(i, 2)
End If
Next
End With
'** tri de la base par N° enregistrement (ordre initial)
' adapter nom de feuille, plage et colonne de tri
With Worksheets("Feuil1")
.Range("I2:K" & .Range("I" & Rows.Count).End(xlUp).Row).Sort Key1:=.Range("I3"), _
Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
End With
' ** fin tri
End Sub