Erreur 1004

Bonjour à tous.

Pourriez-vous m'expliquer pourquoi ma macro plante alors que tout les paramètres me semblent corrects.

Le problème a l'air de venir de

Range(Cells(plt3, 6), Cells(dlt3, 6))

Merci de vos réponses

Sub Macro2()
Dim plt1 As Integer
Dim dlt1 As Integer
Dim plt2 As Integer
Dim dlt2 As Integer
Dim plt3 As Integer
Dim dlt3 As Integer
Dim plt4 As Integer
Dim dlt4 As Integer
Dim dlpr As Integer

plt1 = 7
dlt1 = Sheets("BDD articles").Range("F" & plt1).End(xlDown).Row
plt2 = dlt1 + 4
dlt2 = Sheets("BDD articles").Range("F" & plt2).End(xlDown).Row
plt3 = dlt2 + 4
dlt3 = Sheets("BDD articles").Range("F" & plt3).End(xlDown).Row
plt4 = dlt3 + 4
dlt4 = Sheets("BDD articles").Range("F" & plt4).End(xlDown).Row

Sheets("BDD articles").Range(Cells(plt3, 6), Cells(dlt3, 6)).Copy Destination:=Sheets("tata").Range("B4") ' la macro plante ici
Sheets("BDD articles").Range(Cells(plt3, 5), Cells(dlt3, 5)).Copy Destination:=Sheets("tata").Range("C4")
dlpr = Sheets("tata").Range("B" & Rows.Count).End(xlUp).Row

Sheets("tata").Range("$B$4:$C$" & dlpr).RemoveDuplicates Columns:=1, Header:=xlNo

End Sub

Bonjour,

ta feuille "tata" existe-t-elle ?

Oui la feuille "tata" et la feuille "BDD articles" existent

Si je remplace

Range(Cells(plt3, 6), Cells(dlt3, 6))

par

Range("F33:F66")

ça fonctionne. Donc je pense que le problème vient de là. plt3 et dlt3 ont bien les valeurs 33 et 66 d'après l'explorateur des variables.

Donc mystère pour l'instant.

Bonjour,

Essaie ainsi :

Option Explicit
Sub Macro2()
Dim wsS As Worksheet, wsD As Worksheet
Dim plt1 As Long
Dim dlt1 As Long
Dim plt2 As Long
Dim dlt2 As Long
Dim plt3 As Long
Dim dlt3 As Long
Dim plt4 As Long
Dim dlt4 As Long
Dim dlpr As Long

    Application.ScreenUpdating = False
    Set wsS = Sheets("BDD articles")
    Set wsD = Worksheets("tata")
    plt1 = 7

    With wsS
        dlt1 = .Range("F" & plt1).End(xlDown).Row
        plt2 = dlt1 + 4
        dlt2 = .Range("F" & plt2).End(xlDown).Row
        plt3 = dlt2 + 4
        dlt3 = .Range("F" & plt3).End(xlDown).Row
        plt4 = dlt3 + 4
        dlt4 = .Range("F" & plt4).End(xlDown).Row
        .Range(.Cells(plt3, 6), .Cells(dlt3, 6)).Copy Destination:=wsD.Range("B4")
        .Range(.Cells(plt3, 5), .Cells(dlt3, 5)).Copy Destination:=wsD.Range("C4")
    End With

    With wsD
        dlpr = .Range("B" & Rows.Count).End(xlUp).Row
        .Range("$B$4:$C$" & dlpr).RemoveDuplicates Columns:=1, Header:=xlNo
    End With

    Set wsS = Nothing: Set wsD = Nothing

End Sub

Merci Jean-Eric.

Mon problème est résolu.

Je ne comprends toujours pas pourquoi ça n'allait pas. J'ai toujours fait comme cela et je n'avais pas de plantage...

Bref résolu.

Encore merci.

Rechercher des sujets similaires à "erreur 1004"