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
| Option Explicit
Option Compare Text
Public Sub insert_rows()
Dim derlign As Integer, l As Integer, k As Integer, d As Integer
With Worksheets(1)
derlign = .Cells(.Rows.Count, 1).End(xlUp).Row
For l = derlign To 2 Step -1
With .Cells(l, 1)
If .Value = "Mr" Or .Value = "Mme" Then
k = .End(xlUp).Row
Select Case True
Case (l - k) < 7
Do
.EntireRow.Insert
'Debug.Print Cells(l, 1).End(xlDown).Row
'Debug.Print Cells(l, 1).End(xlUp).Row
d = Cells(l, 1).End(xlDown).Row - Cells(l, 1).End(xlUp).Row
Loop Until d = 7
Case (l - k) > 7
Do
'Debug.Print l & " / " & k & " / " & Cells(l, 1).End(xlUp).Row
.End(xlUp).Offset(1, 0).EntireRow.Delete
'Debug.Print Cells(l, 1).End(xlDown).Row
d = Cells(l, 1).Row - Cells(l - 1, 1).End(xlUp).Row
Loop Until d = 7
End Select
End If
End With
Next l
.Rows("2:6").EntireRow.Delete
End With
End Sub |