clochette
-
Modifié par clochette le 14/02/2013 à 12:54
pijaku
Messages postés12263Date d'inscriptionjeudi 15 mai 2008StatutModérateurDernière intervention 4 janvier 2024
-
14 févr. 2013 à 15:28
Bonjour,
Lorsque j'exécute une macro, l'erreur d'exécution 1004 apparait.
J'ai reparammetré les variable en long, mais le problème persiste.
Je débute et je n'arrive pas à trouver l'erreur...
Ci-dessous le code associé :
Sub SURVEILLANCE_Clic()
Dim i As Long
Dim j As Long
Dim k As Long
Dim dernière_ligne_Article As Long
Dim dernière_ligne_CDC As Long
Dim dernière_ligne_Nomenclature As Long
'
' SURVEILLANCE_Clic Macro
'
Worksheets("Extracts").Select
'Calcul de la dernière ligne Article
Range("A6").Select
Selection.End(xlDown).Select
dernière_ligne_Article = ActiveCell.Row
'Calcul de la dernière ligne CDC
Range("D6").Select
Selection.End(xlDown).Select
dernière_ligne_CDC = ActiveCell.Row
'Calcul de la dernière ligne nomenclature
Range("K6").Select
Selection.End(xlDown).Select
dernière_ligne_Nomenclature = ActiveCell.Row
Private Sub Surveillance_Article()
'
' Macro1 Macro
'
Dim i As Long
Dim j As Long
Dim k As Long
Dim dernière_ligne_000 As Long
Dim dernière_ligne As Long
Dim dernière_ligne_S_E As Long
Worksheets("000 <-> SE").Select
'Calcul de la dernière ligne
Range("A4").Select
Selection.End(xlDown).Select
dernière_ligne = ActiveCell.Row + 1
'On affiche la feuille "Farfouille"
Sheets("Farfouille").Visible = True
'On recense les articles en 000
i = 5
For k = 5 To dernière_ligne
If Right(Cells(k, 1), 3) = "000" Then
Cells(i, 4).Value = Cells(k, 1)
i = i + 1
End If
Next k
'On recense les S/E
i = 5
For k = i To dernière_ligne
If Right(Cells(k, 1), 3) <> "000" Then
Cells(i, 7).Value = Cells(k, 1)
i = i + 1
End If
Next k
'Calcul de la dernière ligne des articles en 000
Range("D4").Select
Selection.End(xlDown).Select
dernière_ligne_000 = ActiveCell.Row
'Calcul de la dernière ligne des S/E
Range("G4").Select
Selection.End(xlDown).Select
dernière_ligne_S_E = ActiveCell.Row
'On copie les 14 digits de gauche des articles en 000 dans l'onglet Farfouille
Range("D5:D" & dernière_ligne_000).Select
Selection.Copy
Worksheets("Farfouille").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
For i = 2 To dernière_ligne_000 - 3
Cells(i, 2).Value = Left(Cells(i, 1), 14)
Next i
Worksheets("000 <-> SE").Select
'On copie les 14 digits de gauche des S/E dans l'onglet Farfouille
Range("G5:G" & dernière_ligne_S_E).Select
Selection.Copy
Worksheets("Farfouille").Select
Range("C2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
For i = 2 To dernière_ligne_S_E - 3
Cells(i, 4).Value = Left(Cells(i, 3), 14)
Next i
Worksheets("000 <-> SE").Select
'On s'assure qu'il existe un article en 000 pour chaque S/E
For i = 5 To dernière_ligne_000
Cells(i, 5).Value = "=IF(VLOOKUP(Farfouille!R[-3]C[-3],Farfouille!R2C4:R1000C4,1,FALSE)=LEFT('000 <-> SE'!RC[-1],14),""OUI"",""NON"")"
Next i
'On s'assure qu'il existe un S/E pour chaque article en 000
For i = 5 To dernière_ligne_S_E
Cells(i, 8).Value = "=IF(VLOOKUP(Farfouille!R[-3]C[-4],Farfouille!R2C2:R1000C2,1,FALSE)=LEFT('000 <-> SE'!RC[-1],14),""OUI"",""NON"")"
Next i
'On sort les Articles en "000" sans S/E
Worksheets("Farfouille").Select
j = 2
k = 2
i = 2
While i < dernière_ligne_000 - 2
While Cells(i, 2).Value <> Cells(k, 4).Value And k < dernière_ligne_S_E - 1
k = k + 1
If k = dernière_ligne_S_E - 2 Then
Cells(j, 5).Value = Cells(i, 1).Value
j = j + 1
k = 2
i = i + 1
End If
Wend
i = i + 1
Wend
'On sort les S/E sans article en "000"
j = 2
k = 2
i = 2
While k < dernière_ligne_S_E - 2
While Cells(i, 2).Value <> Cells(k, 4).Value And i < dernière_ligne_000 - 1
i = i + 1
If i = dernière_ligne_000 - 2 Then
Cells(j, 6).Value = Cells(k, 3).Value
j = j + 1
i = 2
k = k + 1
End If
Wend
k = k + 1
Wend
'On affiche les Article en "000" qui n'ont pas de S/E
Range("E2").Select
Selection.End(xlDown).Select
dernière_ligne_filtre_000 = ActiveCell.Row
Worksheets("000 <-> SE").Select
For i = 5 To dernière_ligne_filtre_000 + 3
Cells(i, 10).Value = Worksheets("Farfouille").Cells(i - 3, 5).Value
Cells(i, 11).Value = "=VLOOKUP(RC[-1],R2C1:R1000C2,2,FALSE)"
Next i
For i = 5 To dernière_ligne_filtre_SE + 3
Cells(i, 13).Value = Worksheets("Farfouille").Cells(i - 3, 6).Value
Cells(i, 14).Value = "=VLOOKUP(RC[-1],R2C1:R1000C2,2,FALSE)"
Next i
'On vide et on cache la feuille "Farfouille"
Worksheets("Farfouille").Select
Range("A2:F" & dernière_ligne).Select
'Selection.Delete
Worksheets("000 <-> SE").Select
Sheets("Farfouille").Visible = False
Range("A1").Select
End Sub
Private Sub Surveillance_CDC()
'
' Macro1 Macro
'
Dim i As Long
Dim j As Long
Dim k As Long
Dim dernière_ligne_000 As Long
Dim dernière_ligne As Long
Dim dernière_ligne_S_E As Long
Worksheets("CDC <-> 000").Select
'Calcul de la dernière ligne
Range("A4").Select
Selection.End(xlDown).Select
dernière_ligne = ActiveCell.Row + 1
'On affiche la feuille "Trifouille"
Sheets("Farfouille").Visible = True
'On filtre les CDC pour ne garder que ceux au statut VP et VL
For i = 0 To dernière_ligne - 5
If Cells(dernière_ligne - i, 5).Value <> "VP" Then
If Cells(dernière_ligne - i, 5).Value <> "VL" Then
Rows(dernière_ligne - i).Delete
End If
End If
Next i
'On recalcule la dernière ligne
Range("A4").Select
Selection.End(xlDown).Select
dernière_ligne = ActiveCell.Row
'On ne garde que les dernières versions des CDC
For j = 0 To dernière_ligne - 5
If Cells(dernière_ligne - j, 1).Value = Cells(dernière_ligne - j - 1, 1).Value Then
Rows(dernière_ligne - j - 1).Delete
End If
Next j
'On recalcule la dernière ligne
Range("A4").Select
Selection.End(xlDown).Select
dernière_ligne = ActiveCell.Row
'Calcul de la dernière ligne des articles en 000 dans "Farfouille"
Worksheets("Farfouille").Select
Range("A2").Select
Selection.End(xlDown).Select
dernière_ligne_000 = ActiveCell.Row
'On compare la base de CDC avec les Articles en "000"
Worksheets("CDC <-> 000").Select
Range("A5:A" & dernière_ligne).Select
Selection.Copy
Worksheets("Farfouille").Select
Range("G2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
'On sort les CDC sans article en "000"
j = 2
k = 2
For i = 2 To dernière_ligne - 2
While Cells(i, 7).Value <> Cells(k, 1).Value And k < dernière_ligne_000 + 1 And i < dernière_ligne - 1
k = k + 1
If k = dernière_ligne_000 Then
Cells(j, 8).Value = Cells(i, 7).Value
j = j + 1
k = 2
i = i + 1
End If
Wend
Next i
'On sort les articles en "000" sans CDC
j = 2
k = 2
i = 2
While i < dernière_ligne_000
While Cells(k, 7).Value <> Cells(i, 1).Value And k < dernière_ligne - 2
k = k + 1
If k = dernière_ligne - 3 Then
Cells(j, 9).Value = Cells(i, 1).Value
j = j + 1
k = 2
i = i + 1
End If
Wend
i = i + 1
Wend
'Calcul de la dernière ligne des CDC sans 000 dans "Farfouille"
Worksheets("Farfouille").Select
Range("H2").Select
Selection.End(xlDown).Select
dernière_ligne_CDC = ActiveCell.Row
'On sort les nomenclatures sans article en "000"
j = 2
k = 2
For i = 2 To dernière_ligne - 3
While Cells(i, 12).Value <> Cells(k, 1).Value And k < dernière_ligne_000 + 1 And i < dernière_ligne - 1
k = k + 1
If k = dernière_ligne_000 + 1 Then
Cells(j, 13).Value = Cells(i, 12).Value
j = j + 1
k = 2
i = i + 1
End If
Wend
Next i
'On sort les article en "000" sans nomenclature
j = 2
k = 2
For i = 2 To dernière_ligne_000 - 3
While Cells(k, 12).Value <> Cells(i, 1).Value And k < dernière_ligne - 1 And i < dernière_ligne_000 + 1
k = k + 1
If k = dernière_ligne - 1 Then
Cells(j, 14).Value = Cells(i, 1).Value
j = j + 1
k = 2
i = i + 1
End If
Wend
Next i
'Calcul de la dernière ligne des articles en 000 sans nomenclature
Range("N2").Select
Selection.End(xlDown).Select
dernière_ligne_000_Nomenclature = ActiveCell.Row
For i = 2 To dernière_ligne_000_Nomenclature
Cells(i, 15).Value = "=VLOOKUP(RC[-1],R2C10:R1000C11,2,FALSE)"
Next i
'On affiche les résultats
Range("M2:M" & dernière_ligne).Select
Selection.Copy
Worksheets("Nomenclature <-> Article").Select
Range("G5").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
For i = 5 To dernière_ligne
Cells(i, 8).Value = "=VLOOKUP(RC[-1],R5C1:R1000C5,5,FALSE)"
Next i
Bonjour,
bonjour pijaku, je comprend ta réaction, mais une directive serait peut-être plus appropriée.
@clochette
Dis au moins où ton code "flanche".(sur quel ligne)
Et poste une exemple de ton classeur (sur https://www.cjoint.com/ par exemple) sans données confidentielle et mettre le lien donner sur un poste suivant.
Et pijaku se fera un plaisir de te guidé pour la suite. :-))
A+
Si tu te cognes à un pot et que ça sonne creux, c'est pas forcément le pot qui est vide. ;-)(Confucius)
Note: Je ne répond pas aux MP pour les questions techniques. Et ma boule de cristal est cassée .
pijaku
Messages postés12263Date d'inscriptionjeudi 15 mai 2008StatutModérateurDernière intervention 4 janvier 20242 743 14 févr. 2013 à 15:28
Salut Lermite222,
oui, en effet, tu as raison. Seulement quand j'ai posté ma réponse, il n'y avait pas du tout de code... D'ou ma réaction ironique.
Modifié par clochette le 14/02/2013 à 12:54 Voili Voila.
Bonne journée à toi