Besoin d'aide
svp mon code ne reconnais pas les instructions "if"
Private Sub CommandButton3_Click()
Dim c As String
Dim b As String
Dim Chemin As String
c = ComboBox1.Value
b = ComboBox2.Value
Chemin = "D:\fichier sysdos\objectifs\" & c & ".xlsx"
Workbooks.Open Chemin
Workbooks("" & c & ".xlsx").Worksheets("objectif_structure_production").Activate
If ComboBox2.Value = "JANVIER " Then
a1 = Sheets("objectif_structure_production").Cells(4, 3)
a2 = Sheets("objectif_structure_production").Cells(8, 3)
a3 = Sheets("objectif_structure_production").Cells(12, 3)
a4 = Sheets("objectif_structure_production").Cells(16, 3)
a5 = Sheets("objectif_structure_production").Cells(20, 3)
a6 = Sheets("objectif_structure_production").Cells(24, 3)
a7 = Sheets("objectif_structure_production").Cells(28, 3)
a8 = Sheets("objectif_structure_production").Cells(32, 3)
a9 = Sheets("objectif_structure_production").Cells(36, 3)
a10 = Sheets("objectif_structure_production").Cells(40, 3)
a11 = Sheets("objectif_structure_production").Cells(44, 3)
a12 = Sheets("objectif_structure_production").Cells(48, 3)
a13 = Sheets("objectif_structure_production").Cells(52, 3)
a14 = Sheets("objectif_structure_production").Cells(56, 3)
a15 = Sheets("objectif_structure_production").Cells(60, 3)
a16 = Sheets("objectif_structure_production").Cells(64, 3)
Else
'If ComboBox2.Value = "fevrier" Then
a1 = Sheets("objectif_structure_production").Cells(4, 4)
a2 = Sheets("objectif_structure_production").Cells(8, 4)
a3 = Sheets("objectif_structure_production").Cells(12, 4)
a4 = Sheets("objectif_structure_production").Cells(16, 4)
a5 = Sheets("objectif_structure_production").Cells(20, 4)
a6 = Sheets("objectif_structure_production").Cells(24, 4)
a7 = Sheets("objectif_structure_production").Cells(28, 4)
a8 = Sheets("objectif_structure_production").Cells(32, 4)
a9 = Sheets("objectif_structure_production").Cells(36, 4)
a10 = Sheets("objectif_structure_production").Cells(40, 4)
a11 = Sheets("objectif_structure_production").Cells(44, 4)
a12 = Sheets("objectif_structure_production").Cells(48, 4)
a13 = Sheets("objectif_structure_production").Cells(52, 4)
a14 = Sheets("objectif_structure_production").Cells(56, 4)
a15 = Sheets("objectif_structure_production").Cells(60, 4)
a16 = Sheets("objectif_structure_production").Cells(64, 4)
'End If
'Else
If ComboBox2.Value = "mars" Then
a1 = Sheets("objectif_structure_production").Cells(4, 5)
a2 = Sheets("objectif_structure_production").Cells(8, 5)
a3 = Sheets("objectif_structure_production").Cells(12, 5)
a4 = Sheets("objectif_structure_production").Cells(16, 5)
a5 = Sheets("objectif_structure_production").Cells(20, 5)
a6 = Sheets("objectif_structure_production").Cells(24, 5)
a7 = Sheets("objectif_structure_production").Cells(28, 5)
a8 = Sheets("objectif_structure_production").Cells(32, 5)
a9 = Sheets("objectif_structure_production").Cells(36, 5)
a10 = Sheets("objectif_structure_production").Cells(40, 5)
a11 = Sheets("objectif_structure_production").Cells(44, 5)
a12 = Sheets("objectif_structure_production").Cells(48, 5)
a13 = Sheets("objectif_structure_production").Cells(52, 5)
a14 = Sheets("objectif_structure_production").Cells(56, 5)
a15 = Sheets("objectif_structure_production").Cells(60, 5)
a16 = Sheets("objectif_structure_production").Cells(64, 5)
'End If
Else
If ComboBox2.Value = "avril" Then
a1 = Sheets("objectif_structure_production").Cells(4, 6)
a2 = Sheets("objectif_structure_production").Cells(8, 6)
a3 = Sheets("objectif_structure_production").Cells(12, 6)
a4 = Sheets("objectif_structure_production").Cells(16, 6)
a5 = Sheets("objectif_structure_production").Cells(20, 6)
a6 = Sheets("objectif_structure_production").Cells(24, 6)
a7 = Sheets("objectif_structure_production").Cells(28, 6)
a8 = Sheets("objectif_structure_production").Cells(32, 6)
a9 = Sheets("objectif_structure_production").Cells(36, 6)
a10 = Sheets("objectif_structure_production").Cells(40, 6)
a11 = Sheets("objectif_structure_production").Cells(44, 6)
a12 = Sheets("objectif_structure_production").Cells(48, 6)
a13 = Sheets("objectif_structure_production").Cells(52, 6)
a14 = Sheets("objectif_structure_production").Cells(56, 6)
a15 = Sheets("objectif_structure_production").Cells(60, 6)
a16 = Sheets("objectif_structure_production").Cells(64, 6)
Else
If ComboBox2.Value = "mai" Then
a1 = Sheets("objectif_structure_production").Cells(4, 7)
a2 = Sheets("objectif_structure_production").Cells(8, 7)
a3 = Sheets("objectif_structure_production").Cells(12, 7)
a4 = Sheets("objectif_structure_production").Cells(16, 7)
a5 = Sheets("objectif_structure_production").Cells(20, 7)
a6 = Sheets("objectif_structure_production").Cells(24, 7)
a7 = Sheets("objectif_structure_production").Cells(28, 7)
a8 = Sheets("objectif_structure_production").Cells(32, 7)
a9 = Sheets("objectif_structure_production").Cells(36, 7)
a10 = Sheets("objectif_structure_production").Cells(40, 7)
a11 = Sheets("objectif_structure_production").Cells(44, 7)
a12 = Sheets("objectif_structure_production").Cells(48, 7)
a13 = Sheets("objectif_structure_production").Cells(52, 7)
a14 = Sheets("objectif_structure_production").Cells(56, 7)
a15 = Sheets("objectif_structure_production").Cells(60, 7)
a16 = Sheets("objectif_structure_production").Cells(64, 7)
Else
If ComboBox2.Value = "juin" Then
a1 = Sheets("objectif_structure_production").Cells(4, 8)
a2 = Sheets("objectif_structure_production").Cells(8, 8)
a3 = Sheets("objectif_structure_production").Cells(12, 8)
a4 = Sheets("objectif_structure_production").Cells(16, 8)
a5 = Sheets("objectif_structure_production").Cells(20, 8)
a6 = Sheets("objectif_structure_production").Cells(24, 8)
a7 = Sheets("objectif_structure_production").Cells(28, 8)
a8 = Sheets("objectif_structure_production").Cells(32, 8)
a9 = Sheets("objectif_structure_production").Cells(36, 8)
a10 = Sheets("objectif_structure_production").Cells(40, 8)
a11 = Sheets("objectif_structure_production").Cells(44, 8)
a12 = Sheets("objectif_structure_production").Cells(48, 8)
a13 = Sheets("objectif_structure_production").Cells(52, 8)
a14 = Sheets("objectif_structure_production").Cells(56, 8)
a15 = Sheets("objectif_structure_production").Cells(60, 8)
a16 = Sheets("objectif_structure_production").Cells(64, 8)
Else
If ComboBox2.Value = "juillet" Then
a1 = Sheets("objectif_structure_production").Cells(4, 9)
a2 = Sheets("objectif_structure_production").Cells(8, 9)
a3 = Sheets("objectif_structure_production").Cells(12, 9)
a4 = Sheets("objectif_structure_production").Cells(16, 9)
a5 = Sheets("objectif_structure_production").Cells(20, 9)
a6 = Sheets("objectif_structure_production").Cells(24, 9)
a7 = Sheets("objectif_structure_production").Cells(28, 9)
a8 = Sheets("objectif_structure_production").Cells(32, 9)
a9 = Sheets("objectif_structure_production").Cells(36, 9)
a10 = Sheets("objectif_structure_production").Cells(40, 9)
a11 = Sheets("objectif_structure_production").Cells(44, 9)
a12 = Sheets("objectif_structure_production").Cells(48, 9)
a13 = Sheets("objectif_structure_production").Cells(52, 9)
a14 = Sheets("objectif_structure_production").Cells(56, 9)
a15 = Sheets("objectif_structure_production").Cells(60, 9)
a16 = Sheets("objectif_structure_production").Cells(64, 9)
Else
If ComboBox2.Value = "aout" Then
a1 = Sheets("objectif_structure_production").Cells(4, 10)
a2 = Sheets("objectif_structure_production").Cells(8, 10)
a3 = Sheets("objectif_structure_production").Cells(12, 10)
a4 = Sheets("objectif_structure_production").Cells(16, 10)
a5 = Sheets("objectif_structure_production").Cells(20, 10)
a6 = Sheets("objectif_structure_production").Cells(24, 10)
a7 = Sheets("objectif_structure_production").Cells(28, 10)
a8 = Sheets("objectif_structure_production").Cells(32, 10)
a9 = Sheets("objectif_structure_production").Cells(36, 10)
a10 = Sheets("objectif_structure_production").Cells(40, 10)
a11 = Sheets("objectif_structure_production").Cells(44, 10)
a12 = Sheets("objectif_structure_production").Cells(48, 10)
a13 = Sheets("objectif_structure_production").Cells(52, 10)
a14 = Sheets("objectif_structure_production").Cells(56, 10)
a15 = Sheets("objectif_structure_production").Cells(60, 10)
a16 = Sheets("objectif_structure_production").Cells(64, 10)
Else
If ComboBox2.Value = "septembre" Then
a1 = Sheets("objectif_structure_production").Cells(4, 11)
a2 = Sheets("objectif_structure_production").Cells(8, 11)
a3 = Sheets("objectif_structure_production").Cells(12, 11)
a4 = Sheets("objectif_structure_production").Cells(16, 11)
a5 = Sheets("objectif_structure_production").Cells(20, 11)
a6 = Sheets("objectif_structure_production").Cells(24, 11)
a7 = Sheets("objectif_structure_production").Cells(28, 11)
a8 = Sheets("objectif_structure_production").Cells(32, 11)
a9 = Sheets("objectif_structure_production").Cells(36, 11)
a10 = Sheets("objectif_structure_production").Cells(40, 11)
a11 = Sheets("objectif_structure_production").Cells(44, 11)
a12 = Sheets("objectif_structure_production").Cells(48, 11)
a13 = Sheets("objectif_structure_production").Cells(52, 11)
a14 = Sheets("objectif_structure_production").Cells(56, 11)
a15 = Sheets("objectif_structure_production").Cells(60, 11)
a16 = Sheets("objectif_structure_production").Cells(64, 11)
Else
If ComboBox2.Value = "octobre" Then
a1 = Sheets("objectif_structure_production").Cells(4, 12)
a2 = Sheets("objectif_structure_production").Cells(8, 12)
a3 = Sheets("objectif_structure_production").Cells(12, 12)
a4 = Sheets("objectif_structure_production").Cells(16, 12)
a5 = Sheets("objectif_structure_production").Cells(20, 12)
a6 = Sheets("objectif_structure_production").Cells(24, 12)
a7 = Sheets("objectif_structure_production").Cells(28, 12)
a8 = Sheets("objectif_structure_production").Cells(32, 12)
a9 = Sheets("objectif_structure_production").Cells(36, 12)
a10 = Sheets("objectif_structure_production").Cells(40, 12)
a11 = Sheets("objectif_structure_production").Cells(44, 12)
a12 = Sheets("objectif_structure_production").Cells(48, 12)
a13 = Sheets("objectif_structure_production").Cells(52, 12)
a14 = Sheets("objectif_structure_production").Cells(56, 12)
a15 = Sheets("objectif_structure_production").Cells(60, 12)
a16 = Sheets("objectif_structure_production").Cells(64, 12)
Else
If ComboBox2.Value = "novembre" Then
a1 = Sheets("objectif_structure_production").Cells(4, 13)
a2 = Sheets("objectif_structure_production").Cells(8, 13)
a3 = Sheets("objectif_structure_production").Cells(12, 13)
a4 = Sheets("objectif_structure_production").Cells(16, 13)
a5 = Sheets("objectif_structure_production").Cells(20, 13)
a6 = Sheets("objectif_structure_production").Cells(24, 13)
a7 = Sheets("objectif_structure_production").Cells(28, 13)
a8 = Sheets("objectif_structure_production").Cells(32, 13)
a9 = Sheets("objectif_structure_production").Cells(36, 13)
a10 = Sheets("objectif_structure_production").Cells(40, 13)
a11 = Sheets("objectif_structure_production").Cells(44, 13)
a12 = Sheets("objectif_structure_production").Cells(48, 13)
a13 = Sheets("objectif_structure_production").Cells(52, 13)
a14 = Sheets("objectif_structure_production").Cells(56, 13)
a15 = Sheets("objectif_structure_production").Cells(60, 13)
a16 = Sheets("objectif_structure_production").Cells(64, 13)
else
If ComboBox2.Value = "decembre" Then
a1 = Sheets("objectif_structure_production").Cells(4, 14)
a2 = Sheets("objectif_structure_production").Cells(8, 14)
a3 = Sheets("objectif_structure_production").Cells(12, 14)
a4 = Sheets("objectif_structure_production").Cells(16, 14)
a5 = Sheets("objectif_structure_production").Cells(20, 14)
a6 = Sheets("objectif_structure_production").Cells(24, 14)
a7 = Sheets("objectif_structure_production").Cells(28, 14)
a8 = Sheets("objectif_structure_production").Cells(32, 14)
a9 = Sheets("objectif_structure_production").Cells(36, 14)
a10 = Sheets("objectif_structure_production").Cells(40, 14)
a11 = Sheets("objectif_structure_production").Cells(44, 14)
a12 = Sheets("objectif_structure_production").Cells(48, 14)
a13 = Sheets("objectif_structure_production").Cells(52, 14)
a14 = Sheets("objectif_structure_production").Cells(56, 14)
a15 = Sheets("objectif_structure_production").Cells(60, 14)
a16 = Sheets("objectif_structure_production").Cells(64, 14)
'End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Workbooks("" & c & "").Close True
end
- Messages
- 2'415
- Excel
- 2019
- Inscrit
- 13/07/2017
- Emploi
- Formateur, animateur,tech.informatique
Bonjour
Tu aurais du mettre ton code dans la balise 'code' tu peux toujours rééditer ton post et le modifier
en essayant :
ElseIf ComboBox2.Value = "fevrier" Then
idem pour les autres...
crdlt,
Andre
desolé ANDRE mais ça ne reconnait toujours pas
Salut
Certains de tes "if" sont en commentaires ('if) et il faut enlever les "end if" à la fin de février et mars.
Par contre, cela aurait été beaucoup plus lisible de faire un select
avec
MonMois = Combobox2.Value
j=0
Select case MomMois
Case Is = "Janvier"
j=3
Case Is = "Février"
j=4
...
Case Is = "Décembre"
j=14
End Select
a1 = Sheets("objectif_structure_production").Cells(4, j)
a2 = Sheets("objectif_structure_production").Cells(8, j)
a3 = Sheets("objectif_structure_production").Cells(12, j)
a4 = Sheets("objectif_structure_production").Cells(16, j)
a5 = Sheets("objectif_structure_production").Cells(20, j)
a6 = Sheets("objectif_structure_production").Cells(24, j)
a7 = Sheets("objectif_structure_production").Cells(28, j)
a8 = Sheets("objectif_structure_production").Cells(32, j)
a9 = Sheets("objectif_structure_production").Cells(36, j)
a10 = Sheets("objectif_structure_production").Cells(40, j)
a11 = Sheets("objectif_structure_production").Cells(44, j)
a12 = Sheets("objectif_structure_production").Cells(48, j)
a13 = Sheets("objectif_structure_production").Cells(52, j)
a14 = Sheets("objectif_structure_production").Cells(56, j)
a15 = Sheets("objectif_structure_production").Cells(60, j)
a16 = Sheets("objectif_structure_production").Cells(64, j)
jers19 desolé ça ne donne pas
Ca veut dire quoi ?
Quel est le problème ? Il y a t'il un message d'erreur ?
Jers19 ça affiche " erreur définie par l application ou par l objet"
Et le débogage m envoie à la première ligne sous "End select"
Oui j'ai fait une erreur
Il faut remplacer "Select case MomMois" par "Select case MonMois"
Jers19 j avais déjà vu cette et j ai corrigé mais toujours rien
Et si tu remplaces MonMois = Combobox2.Value par MonMois="Janvier" et que tu exécutes le code en mode pas à pas,
la valeur de j est correct (=3 dans notre exemple)
Ca serait plus simple si tu posté ton fichier.
Tu peux aussi exécuté le code en mode pas à pas afin de voir si la variable j est bien incrémentée.
Car cette erreur est générée si j=0 (cellule inexistante)
Vérifie aussi que les valeurs de la combobox sont strictement identiques avec les valeurs indiquées dans le "case" en faisant attention aux majuscules et aux accents.
Jers19 je comprends pas
jers19 merci ça marche c'etait un probleme de majuscule
Ok parfait.
Merci de clôturer le sujet si tout est ok.