Boucle copier coller à la prochaine ligne vide à partir d'une ligne
Bonjour à tous,
Pouvez-vous m'aider svp sur ma boucle.J'aimerais copié collé à partir de mon onglet data toutes lignes non vide à partir de A4 avec une condition vers d'autres onglets également à partir de A4.
Voici le code que j'ai ecrit. Je pense que mon probleme vient "Cells" que je n'ai pas défini mais comment dois je le définir?
Merci par avance pour votre aide ;-)
Worksheets("Data").Activate
Dim cellule
Dim nombre As Integer
Dim i&
nombre = Range("A" & Rows.Count).End(xlUp).Row
For i = 4 To nombre
If Range("A" & i).Value = 1 Then 'test si la condition est respectée
Range("B" & i & ":ME" & i).Copy 'alors je copie ce dont j'ai besoin
Sheets("1").Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues 'je voudrais copié alors sur la prochaine ligne non vide à partir de A4
Sheets("2").Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Sheets("3").Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Sheets("4").Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Sheets("11").Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Sheets("22").Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Sheets("33").Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Sheets("44").Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
End If
Next i
Edit modo : merci de mettre le code entre balises grâce au bouton </>
Bonjour Marchal_x
Voici un code à tester
Sub Copie()
Dim dLig As Long, Lig As Long
Dim Sht As Worksheet
' Définir la feuille source
Set Sht = Worksheets("Data")
' Dernière ligne remplie de la feuille
dLig = Sht.Range("A" & Rows.Count).End(xlUp).Row
' Pour chaque ligne
For Lig = 4 To dLig
' Si la cellule A de la ligne est remplie
If Sht.Range("A" & Lig).Value = 1 Then
' Copier les donnée Y COMPRIS A
Sht.Range("A" & Lig & ":ME" & Lig).Copy
' Coller les données
With Sheets(1)
.Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
End With
With Sheets(2)
.Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
End With
With Sheets(3)
.Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
End With
With Sheets(4)
.Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
End With
With Sheets(11)
.Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
End With
With Sheets(22)
.Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
End With
With Sheets(33)
.Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
End With
With Sheets(44)
.Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
End With
End If
Next Lig
End Sub
En ce qui concerne les chiffres entre guillemets
Soit tu as des onglets qui se nomme "1", "2", Etc...
Et donc ton code est correcte
Soit tu as un onglet numéro 1, 2, etc....
Et là, c'est le mine qui est correcte
@+
Bonjour Bruno,
Super, je viens de tester, cela marche parfaitement!!! et j'ai bien compris ta méthodologie!
MERCI !!!!!!