Bonjour à tous,
je travaille actuellement sur un fichier Excel codé en VBA. Je cherche à créer un planning (pj n°1) en fonction d'un en-cours d'atelier (pj n°2).
Le problème est que mon planning écrit les mêmes dossiers de fabrication en boucle (voir pj n°1). Je pense que mon problème est dû à ma boucle j qui ne prends pas en compte ma variable i mais je ne vois pas comment faire.
Voilà la fonction initiale avec ma variable i :
et ma fonction "fraisage" avec ma variable j :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 Public Sub MAJplanning() Dim i As Single, finPage As Single Sheets("MECA").Activate finPage = Sheets("MECA").Cells(Rows.Count, 2).End(xlUp).Row For i = 2 To finPage If Sheets("MECA").Cells(i, 7).Value <> "" Then Call Fraisage(i) ElseIf Sheets("MECA").Cells(i, 8).Value <> "" Then Call Tournage ElseIf Sheets("MECA").Cells(i, 9).Value <> "" Then Call Percage ElseIf Sheets("MECA").Cells(i, 10).Value <> "" Then Call Clavetage ElseIf Sheets("MECA").Cells(i, 11).Value <> "" Then Call Alpha ElseIf Sheets("MECA").Cells(i, 12).Value <> "" Then Call CTX ElseIf Sheets("MECA").Cells(i, 13).Value <> "" Then Call CU End If Next End Sub
Merci d'avance pour votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 Public Sub Fraisage(i As Single) Dim j As Single Sheets("Planning").Activate For j = 0 To 81 Step 3 If Sheets("Planning").Cells(2, 2 + j).Value = "" Then With Sheets("MECA") .Range("B" & i).Copy Sheets("Planning").Cells(2, 2 + j).PasteSpecial .Range("D" & i).Copy Sheets("Planning").Cells(2, 3 + j).PasteSpecial .Range("G" & i).Copy Sheets("Planning").Cells(2, 4 + j).PasteSpecial End With ElseIf Sheets("Planning").Cells(3, 2 + j).Value = "" Then With Sheets("MECA") .Range("B" & i).Copy Sheets("Planning").Cells(3, 2 + j).PasteSpecial .Range("D" & i).Copy Sheets("Planning").Cells(3, 3 + j).PasteSpecial .Range("G" & i).Copy Sheets("Planning").Cells(3, 4 + j).PasteSpecial End With ElseIf Sheets("Planning").Cells(4, 2 + j).Value = "" Then With Sheets("MECA") .Range("B" & i).Copy Sheets("Planning").Cells(4, 2 + j).PasteSpecial .Range("D" & i).Copy Sheets("Planning").Cells(4, 3 + j).PasteSpecial .Range("G" & i).Copy Sheets("Planning").Cells(4, 4 + j).PasteSpecial End With ElseIf Sheets("Planning").Cells(5, 2 + j).Value = "" Then With Sheets("MECA") .Range("B" & i).Copy Sheets("Planning").Cells(5, 2 + j).PasteSpecial .Range("D" & i).Copy Sheets("Planning").Cells(5, 3 + j).PasteSpecial .Range("G" & i).Copy Sheets("Planning").Cells(5, 4 + j).PasteSpecial End With End If Next End Sub![]()
Partager