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
| Sub MiseEnPage()
'
Dim DerLig As Long, r As Long
Dim MaPlage As Range, MaRech As Range
DerLig = Cells(Columns(1).Cells.Count, 1).End(xlUp).Row
Set MaPlage = Sheets("sheet1").Range(Cells(2, 1), Cells(DerLig, 1))
'AS, AN, AO, AP, BX, CD
With MaPlage
Set MaRech = .Find("AS", LookIn:=xlValues)
If MaRech Is Nothing Then
DerLig = DerLig + 1
Cells(DerLig, 1) = "AS"
End If
End With
With MaPlage
Set MaRech = .Find("AP", LookIn:=xlValues)
If MaRech Is Nothing Then
DerLig = DerLig + 1
Cells(DerLig, 1) = "AP"
End If
End With
With MaPlage
Set MaRech = .Find("CD", LookIn:=xlValues)
If MaRech Is Nothing Then
DerLig = DerLig + 1
Cells(DerLig, 1) = "CD"
End If
End With
DerLig = Cells(Columns(1).Cells.Count, 1).End(xlUp).Row 'recalcule la dernière
For r = 3 To DerLig + 6 '+6 pour avoir une marge pour les lignes insérées à adapter selon le nombre d'ID
If Cells(r, 1) <> "" Then 'Evite les lignes vides crées
If Cells(r, 1) = Cells(r - 1, 1) Then 'vérifie si = à la ligne précédente
Cells(r, 2).Clear 'efface la valeur car égale à ligne précédente (problème3)
Else
Rows(r).Insert Shift:=xlDown 'Insert une ligne après la ligne en question (problème2)
r = r + 1 'incrémente pour passer la ligne insérée
End If
End If
Next r
End Sub |
Partager