Excel2007 macro insertion lignes

Fermé
Raymond PENTIER Messages postés 58393 Date d'inscription lundi 13 août 2007 Statut Contributeur Dernière intervention 23 avril 2024 - 8 oct. 2009 à 03:29
Raymond PENTIER Messages postés 58393 Date d'inscription lundi 13 août 2007 Statut Contributeur Dernière intervention 23 avril 2024 - 8 oct. 2009 à 13:44
Bonjour aux amateurs de VBA.

Comme vous le savez, je suis nul en macros !
Or je voudrais pouvoir, étant dans une ligne quelconque, lancer une macro qui m'insère 3 lignes vides après la ligne courante.
Et pour éviter de recommencer cette manoeuvre de nombreuses fois, peut-on écrire une macro qui répète cette action depuis une ligne sélectionnée et tant qu'il y a des lignes renseignées ?
https://www.cjoint.com/?kidBJn8265

Merci d'avance de vos diverses contributions.

Cordialement.
A voir également:

2 réponses

UsulArrakis Messages postés 7405 Date d'inscription vendredi 28 mars 2003 Statut Contributeur Dernière intervention 27 janvier 2022 3 182
8 oct. 2009 à 08:38
Bonjour Raymond
fait beau aux Antilles ?

voilà 3 macros que pourrais peut être adapter (ou qq'un d'autre) et qu'on avait faite pour moi
Sub Ajoutligne_complet()
On Error Resume Next 'à cause de la dernière ligne de la colonne A
Dim c As Range
For Each c In Selection
If UCase(c) <> "" Then 'il faut qq chose dans la cellule sinon neutraliser le IF
c.Offset(1, 0).EntireRow.Insert
End If
Next


Range("A" & Selection.Row & ":A" & Selection.Row + 1).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.ShrinkToFit = False
.MergeCells = False
End With
Selection.Merge
Range("B" & Selection.Row & ":B" & Selection.Row + 1).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.ShrinkToFit = False
.MergeCells = False
End With
Selection.Merge
Range("C" & Selection.Row & ":C" & Selection.Row + 1).Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.ShrinkToFit = False
.MergeCells = False
End With
Selection.Merge
Range("F" & Selection.Row & ":F" & Selection.Row + 1).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.ShrinkToFit = False
.MergeCells = False
End With
Selection.Merge
Range("D" & Selection.Row).Select
With Selection
.RowHeight = 15
End With
Range("D" & Selection.Row + 1).Select
With Selection
.RowHeight = 15
End With
End Sub



Sub Ajoutligne_inf()
Dim Ligne
Ligne = ActiveCell.Row + 1
Range("A" & Ligne).EntireRow.Insert
Range("A" & Ligne - 1 & ":A" & Ligne).Merge
Range("B" & Ligne - 1 & ":B" & Ligne).Merge
Range("C" & Ligne - 1 & ":C" & Ligne).Merge
Range("F" & Ligne - 1 & ":F" & Ligne).Merge
Range("D" & Selection.Row).Select
With Selection
.Value = "SRO"
.RowHeight = 15
End With
Range("D" & Selection.Row + 1).Select
With Selection
.Value = "NDB"
.RowHeight = 15
End With

End Sub



Sub Ajoutligne_sup()
Dim Ligne
Ligne = ActiveCell.Row + 1
Range("A" & Ligne).EntireRow.Insert
Range("A" & Ligne - 1 & ":A" & Ligne).Merge
Range("B" & Ligne - 1 & ":B" & Ligne).Merge
Range("C" & Ligne - 1 & ":C" & Ligne).Merge
Range("F" & Ligne - 1 & ":F" & Ligne).Merge
Range("D" & Selection.Row).Select
With Selection
.Value = "SRO"
.RowHeight = 15
End With
Range("D" & Selection.Row + 1).Select
With Selection
.Value = "NDB"
.RowHeight = 15
End With

End Sub
0
Raymond PENTIER Messages postés 58393 Date d'inscription lundi 13 août 2007 Statut Contributeur Dernière intervention 23 avril 2024 17 096
8 oct. 2009 à 13:44
Salut !

Oui, il fait beau (aujourd'hui) aux Antilles ; mais j'ai vu qu'il ne fait pas trop mauvais en Métropole (tout au moins dans certaines régions) ...

Je te remercie beaucoup de ta réponse rapide et, je l'espère bien, efficace : Je m'en vais tester tout ça dans la journée. Il faudra vraiment que j'essaie de m'y mettre pour de bon, à VBA !

Encore merci, et à bientôt.
0