Microsoft 365 Problème avec ma macro

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Patoche42

XLDnaute Junior
Bonjour tous le monde
J'ai essayé de créer une macro mais j'ai message comme quoi il y a problème.
Quelqu'un peu m'expliquer ce qu'y ne va pas ?
merci d'avance

' Copier /coller dans feuil2

lign1 = 1
lign2 = 10
col1 = 9
col2 = 18

Do While g <= 360

Sheets("Feuil1").Range(Cells("lign1,1"), Cells(lign2, 100)).Copy

sheets("Feuil2").Range(Cells("17,col1"), cells("100,col2)).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True


lign1 = lign1 + 10
lign2 = lign2 + 10
col1 = col1 + 12
col2 = col2 + 12


Loop
 
Solution
Sheets("Feuil1").Range(Cells(lign1, 1), Cells(lign2, 100)).Copy

Sheets("Feuil2").Range(Cells(17, col1), Cells(100, col2)).PasteSpecial Paste:=xlPasteAll
Cells(lign1,1), Cells(lign2, 100) ==> cellules de la feuille active
Cells(17, col1), Cells(100, col2) ==> cellules de la feuille active
Prenez l'habitude de toujours désigner précisement la feuille concernée :
VB:
' Copier /coller dans feuil2
Sub test()
    lign1 = 1
    lign2 = 10
    col1 = 9
    col2 = 18
    Set F1 = Worksheets("Feuil1")
    Set F2 = Worksheets("Feuil2")
    
    Do While lign2 <= 360
        F1.Range(F1.Cells(lign1, 1), F1.Cells(lign2, 100)).Copy
        F2.Range(F2.Cells(17, col1), F2.Cells(100, col2)).PasteSpecial _
            Paste:=xlPasteAll...
Bonjour,
Cells("lign1,1") n'est pas bon, Cells(lign1,1) est correct
Cells("17,col1") n'est pas bon, Cells(17,col1) est correct
etc .... 🤗

Do While g <= 360 : quand faites-vous évoluer g ? 🤔
Merci pour ta réponse
Effectivement, à force de bidouiller ma macro j'avais pas vu ça ...
Mais j'ai toujours un soucis sur la même ligne, 'erreur 1004"
Après modification :

' Copier /coller dans feuil2

lign1 = 1
lign2 = 10
col1 = 9
col2 = 18

Do While lign2 <= 360

Sheets("Feuil1").Range(Cells(lign1, 1), Cells(lign2, 100)).Copy

Sheets("Feuil2").Range(Cells(17, col1), Cells(100, col2)).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True

lign1 = lign1 + 10
lign2 = lign2 + 10
col1 = col1 + 12
col2 = col2 + 12
 
Sheets("Feuil1").Range(Cells(lign1, 1), Cells(lign2, 100)).Copy

Sheets("Feuil2").Range(Cells(17, col1), Cells(100, col2)).PasteSpecial Paste:=xlPasteAll
Cells(lign1,1), Cells(lign2, 100) ==> cellules de la feuille active
Cells(17, col1), Cells(100, col2) ==> cellules de la feuille active
Prenez l'habitude de toujours désigner précisement la feuille concernée :
VB:
' Copier /coller dans feuil2
Sub test()
    lign1 = 1
    lign2 = 10
    col1 = 9
    col2 = 18
    Set F1 = Worksheets("Feuil1")
    Set F2 = Worksheets("Feuil2")
    
    Do While lign2 <= 360
        F1.Range(F1.Cells(lign1, 1), F1.Cells(lign2, 100)).Copy
        F2.Range(F2.Cells(17, col1), F2.Cells(100, col2)).PasteSpecial _
            Paste:=xlPasteAll, Transpose:=True
        lign1 = lign1 + 10
        lign2 = lign2 + 10
        col1 = col1 + 12
        col2 = col2 + 12
    Loop
End Sub
 
Sinon le code ci-dessous fait la même chose :
VB:
Sub Test2()
    C = 9
    For L = 1 To 360 Step 10
        Worksheets("Feuil1").Cells(L, 1).Resize(10, 100).Copy
        Worksheets("Feuil2").Cells(17, C).PasteSpecial Paste:=xlPasteAll, Transpose:=True
        C = C + 12
    Next
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
10
Affichages
547
  • Question Question
Microsoft 365 Erreur de format
Réponses
5
Affichages
491
Retour