Microsoft 365 Problème avec ma macro

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...

Patoche42

XLDnaute Junior
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
 

fanch55

XLDnaute Barbatruc
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
 

fanch55

XLDnaute Barbatruc
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
 

Discussions similaires

Réponses
5
Affichages
120
Réponses
3
Affichages
579

Statistiques des forums

Discussions
312 213
Messages
2 086 307
Membres
103 174
dernier inscrit
OBUTT