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
|
Sub duplication()
Dim P As Range 'Plage de cellules
Dim C As Range 'Cellule
Dim T As String 'Titre
Dim F As String 'Feuille
Dim D As Long 'Dernière ligne
Dim L As Long 'Ligne
F = "Base Auto"
T = "Raison Sociale 6"
'Chercher le titre
Set P = Worksheets(F).Rows(1)
Set C = P.Find(what:=T, LookIn:=xlValues, lookat:=xlWhole)
If C Is Nothing Then
P.Parent.Activate
MsgBox "Il n'y a pas de colonne « " & T & " » dans " & F, vbCritical
Exit Sub
End If
Set P = C.EntireColumn
With Worksheets(F)
D = .Cells(.Rows.Count, "A").End(xlUp).Row
For L = D To 2 Step -1
If P.Cells(L, 1).Value <> "" Then
'Dupliquer la ligne
.Rows(L).Insert shift:=xlDown
.Rows(L + 1).Copy Destination:=.Rows(L)
'Déplacer les 2 cellules vers la gauche
P.Cells(L + 1, 1).Resize(1, 2).Cut Destination:=P.Cells(L + 1, 1).Offset(0, -10)
End If
Next L
End With
T = "Raison Sociale 5"
'Chercher le titre
Set P = Worksheets(F).Rows(1)
Set C = P.Find(what:=T, LookIn:=xlValues, lookat:=xlWhole)
If C Is Nothing Then
P.Parent.Activate
MsgBox "Il n'y a pas de colonne « " & T & " » dans " & F, vbCritical
Exit Sub
End If
Set P = C.EntireColumn
With Worksheets(F)
D = .Cells(.Rows.Count, "A").End(xlUp).Row
For L = D To 2 Step -1
If P.Cells(L, 1).Value <> "" Then
'Dupliquer la ligne
.Rows(L).Insert shift:=xlDown
.Rows(L + 1).Copy Destination:=.Rows(L)
'Déplacer les 2 cellules vers la gauche
P.Cells(L + 1, 1).Resize(1, 2).Cut Destination:=P.Cells(L + 1, 1).Offset(0, -8)
End If
Next L
End With
End Sub |
Partager