Erreur 1004

Bonjour, je tente de faire un copier-coller sur une plage X, mon problème est que je veux qu'un bouton active ce copier-coller sur plusieurs page différente. voici mon code :

Sub Formule()

Dim DernLigne As Long
Dim lastcolumn As Long

With Sheets("Liste")
.Cells(5, 3) = Sheets("Liste").Cells(1, 2).Formula
DernLigne = Range("A" & Rows.Count).End(xlUp).Row
Sheets("Liste").Cells(5, 3).AutoFill Destination:=Range("C5", "C" & DernLigne)
Sheets("Liste").Cells(5, 5) = Sheets("Liste").Cells(2, 2).Formula
Sheets("Liste").Cells(5, 5).AutoFill Destination:=Range("E5", "E" & DernLigne)
End With

With Sheets("Actifs")
lastcolumn = Cells(5, Columns.Count).End(xlToLeft).Column
Sheets("actifs").Range("D7").AutoFill Destination:=Range(Sheets("actifs").Cells(7, 4), Sheets("actifs").Cells(7, lastcolumn))
End With

With Sheets("Geo")
lastcolumn = Cells(5, Columns.Count).End(xlToLeft).Column
.Cells(7, 4).AutoFill Destination:=Range(Cells(7, 4), Cells(7, lastcolumn))
End With

End Sub

La section en italique est où apparaît l'erreur

1 réponse

  1. Bonjour Tetro, bonjour el forum,

    Tu oublies souvent le point faisant référence au With devant certains Range ou Cells. Ton code modifié mais non testé :

    Sub Formule()
    Dim DernLigne As Long
    Dim lastcolumn As Integer
    
    With Sheets("Liste")
        .Cells(5, 3).Formula = .Cells(1, 2).Formula
        DernLigne = .Range("A" & Rows.Count).End(xlUp).Row
        .Cells(5, 3).AutoFill Destination:=.Range("C5:C" & DernLigne)
        .Cells(5, 5).Formula = .Cells(2, 2).Formula
        .Cells(5, 5).AutoFill Destination:=.Range("E5:E" & DernLigne)
    End With
    
    With Sheets("Actifs")
        lastcolumn = .Cells(5, Columns.Count).End(xlToLeft).Column
        .Range("D7").AutoFill Destination:=.Range(.Cells(7, 4), .Cells(7, lastcolumn))
    End With
    
    With Sheets("Geo")
        lastcolumn = .Cells(5, Columns.Count).End(xlToLeft).Column
        .Cells(7, 4).AutoFill Destination:=.Range(.Cells(7, 4), .Cells(7, lastcolumn))
    End With
    End Sub