RESOLU - Macro copier une ligne sur nombre de lignes variable

Usine à gaz

XLDnaute Barbatruc
Supporter XLD
Bonjour à toutes et à tous,

Encore un truc que je ne sais pas faire.

J'ai une macro :
Code:
Sub CopieLignesRetoursClients()
'
' CopieLignesRetoursClients Macro
'

'
    
    Application.ScreenUpdating = False
    Sheets("Feuil1").Select
    
    Rows("3:3").Select
    Selection.RowHeight = 25
    Rows("3:3").Select
    Selection.Copy
    ActiveSheet.Cells(Rows.Count, "A").End(xlUp)(2).Select
    ActiveSheet.Paste
    Rows("3:3").Select
    Selection.RowHeight = 0
    Range("A4").Select
    ActiveWorkbook.Save
End Sub

La copie de ma ligne 3 fonctionne maisça me le fait ligne par ligne.

Je voudrais faire 1000 lignes en une seule fois.

Malgré mes recherches et essais, je n'ai pas trouvé comment faire.
Pourriez-vous m'aider ?

Un grand merci à vous tous,
Amicalement,
Calimero,
 

Pièces jointes

  • test forumCopieLigne.xlsm
    18.5 KB · Affichages: 37
Dernière édition:

pierrejean

XLDnaute Barbatruc
Re : Macro copier une ligne sur nombre de lignes variable

Bonjour Calimero

A tester:

Code:
Sub test()
Application.ScreenUpdating = False
Rows("3:3").RowHeight = 25
For n = 1 To 1000
 Rows("3:3").Copy Destination:=Range("A" & n + 3)
Next
Rows("3:3").RowHeight = 0
Application.ScreenUpdating = True
End Sub
 

camarchepas

XLDnaute Barbatruc
Re : Macro copier une ligne sur nombre de lignes variable

Bonjour Caliméro , PierreJean ,

Autre solution sans la boucle :

Code:
Sub CopieLignesRetoursClients()
'
' CopieLignesRetoursClients Macro
'

Dim LigneFin As Long
    
    Application.ScreenUpdating = False
    With Sheets("Feuil1")
      .Rows("3:3").RowHeight = 25
       LigneFin = .Range("A" & .Rows.Count).End(xlUp).Row + 1
      .Range("A3:S3").Copy Destination:=.Range("A" & LigneFin & ":S" & LigneFin).Resize(1000, 1)
      .Rows("3:3").RowHeight = 0
      .Range("A4").Select
    End With
    ActiveWorkbook.Save
    Application.ScreenUpdating = True
End Sub
 

Discussions similaires