Se connecter avec
S'enregistrer | Connectez-vous

vba If et EndIf help please...

Dernière réponse : dans Programmation

salut j'ai un petit pb sur un projet excel. lorsque je compile ca me di ke j'ai un bloc If sans End If ... j'ai beau regarder ms je trouve pas, ca me rend fou aidez moi si vs le pouvez merci bcp :-))

voici le code de la fonction :

Private Sub ajouter_Click()

If marque.alfaRomeo = False And marque.audi = False And marque.bmw = False And marque.citroen = False And marque.ford = False And marque.jaguar = False And marque.lexus = False And marque.mercedes = False And marque.opel = False And marque.peugeot = False And marque.renault = False And marque.toyota = False And marque.volkswagen = False Then
GoTo Erreur
If garantie.garantieOui = False And garantie.garantieNon = False Then GoTo Erreur
If prixbox = 0 Or garantiebox = 0 Then GoTo Erreur
If civilite.monsieur = False And civilite.madame = False And civilite.mademoiselle = False Then GoTo Erreur
If nombox = "" Or prenombox = "" Or adressebox = "" Or cpbox = "" Or villebox = "" Or telbox = "" Then
GoTo Erreur
'definition de la marque
If marque.alfaRomeo Then
Choix = "AlfaRomeo"
ElseIf marque.audi Then
Choix = "Audi"
ElseIf marque.bmw Then
Choix = "BMW"
ElseIf marque.citroen Then
Choix = "Citroen"
ElseIf marque.ford Then
Choix = "Ford"
ElseIf marque.jaguar Then
Choix = "Jaguar"
ElseIf marque.lexus Then
Choix = "Lexus"
ElseIf marque.mercedes Then
Choix = "Mercedes"
ElseIf marque.opel Then
Choix = "Opel"
ElseIf marque.peugeot Then
Choix = "Peugeot"
ElseIf marque.renault Then
Choix = "Renault"
ElseIf marque.toyota Then
Choix = "Toyota"
Else
Choix = "Volkswagen"
End If

If garantiePlus.garantieOui Then
Gar = "Oui"
Else
Gar = "Non"
End If

If civilite.monsieur Then
Civ = "Monsieur"
ElseIf civilite.madame Then
Civ = "Madame"
Else
Civ = "Mademoiselle"
End If


Sheets("SAV").Select
If Range("a2").Value = "" Then
decalage = 0
Range("a2").Select
Else
decalage = 1
Position = Range("A1").End(xlDown).Address
Range(Position).Select
Range("A1").End(xlDown).Select
End If


ActiveCell.Offset(decalage, 0).Range("a1").Select
ActiveCell.Value = Choix
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = MODELE
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = Gar
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = CCur(cout.Value)
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = prixbox
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = garantiebox
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = CCur(cout + garantiebox)
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = Civ
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = UCase(nombox)
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = prenombox
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = adressebox
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = cpbox
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = UCase(villebox)
ActiveCell.Offset(0, 1).Range("a1").Select
ActiveCell.Value = telbox

Sheets("voitures").Select
GoTo fin

Erreur:
Message = MsgBox("Veuillez saisir tous les champs SVP, merci ", vbOKOnly + vbCritical, "Jerem'Concessionnaire")
fin:

End Sub



merci bcp bcp par avance
bonne soiree

jeremy

Autres pages sur : vba endif help please

Lassé par la pub ? Créez un compte
Expert Programmation

Non. Ton code est illisible publié comme ça.
Mais tu as le droit de te tromper et de te corriger :

KangOl te demande d'utiliser la balise CODE. Voici son usage :


A bientôt.

Code corrigé, en espérant qu'il ne soit pas trop tard...

  1. Private Sub ajouter_Click()
  2.  
  3. If marque.alfaRomeo = False And marque.audi = False And marque.bmw = False And marque.citroen = False And marque.ford = False And marque.jaguar = False And marque.lexus = False And marque.mercedes = False And marque.opel = False And marque.peugeot = False And marque.renault = False And marque.toyota = False And marque.volkswagen = False Then
  4. GoTo Erreur
  5. End If
  6. If garantie.garantieOui = False And garantie.garantieNon = False Then GoTo Erreur
  7. If prixbox = 0 Or garantiebox = 0 Then GoTo Erreur
  8. If civilite.monsieur = False And civilite.madame = False And civilite.mademoiselle = False Then GoTo Erreur
  9. If nombox = "" Or prenombox = "" Or adressebox = "" Or cpbox = "" Or villebox = "" Or telbox = "" Then
  10. GoTo Erreur
  11. End If
  12. 'definition de la marque
  13. If marque.alfaRomeo Then
  14. Choix = "AlfaRomeo"
  15. ElseIf marque.audi Then
  16. Choix = "Audi"
  17. ElseIf marque.bmw Then
  18. Choix = "BMW"
  19. ElseIf marque.citroen Then
  20. Choix = "Citroen"
  21. ElseIf marque.ford Then
  22. Choix = "Ford"
  23. ElseIf marque.jaguar Then
  24. Choix = "Jaguar"
  25. ElseIf marque.lexus Then
  26. Choix = "Lexus"
  27. ElseIf marque.mercedes Then
  28. Choix = "Mercedes"
  29. ElseIf marque.opel Then
  30. Choix = "Opel"
  31. ElseIf marque.peugeot Then
  32. Choix = "Peugeot"
  33. ElseIf marque.renault Then
  34. Choix = "Renault"
  35. ElseIf marque.toyota Then
  36. Choix = "Toyota"
  37. Else
  38. Choix = "Volkswagen"
  39. End If
  40.  
  41. If garantiePlus.garantieOui Then
  42. Gar = "Oui"
  43. Else
  44. Gar = "Non"
  45. End If
  46.  
  47. If civilite.monsieur Then
  48. Civ = "Monsieur"
  49. ElseIf civilite.madame Then
  50. Civ = "Madame"
  51. Else
  52. Civ = "Mademoiselle"
  53. End If
  54.  
  55.  
  56. Sheets("SAV").Select
  57. If Range("a2").Value = "" Then
  58. decalage = 0
  59. Range("a2").Select
  60. Else
  61. decalage = 1
  62. Position = Range("A1").End(xlDown).Address
  63. Range(Position).Select
  64. Range("A1").End(xlDown).Select
  65. End If
  66.  
  67.  
  68. ActiveCell.Offset(decalage, 0).Range("a1").Select
  69. ActiveCell.Value = Choix
  70. ActiveCell.Offset(0, 1).Range("a1").Select
  71. ActiveCell.Value = MODELE
  72. ActiveCell.Offset(0, 1).Range("a1").Select
  73. ActiveCell.Value = Gar
  74. ActiveCell.Offset(0, 1).Range("a1").Select
  75. ActiveCell.Value = CCur(cout.Value)
  76. ActiveCell.Offset(0, 1).Range("a1").Select
  77. ActiveCell.Value = prixbox
  78. ActiveCell.Offset(0, 1).Range("a1").Select
  79. ActiveCell.Value = garantiebox
  80. ActiveCell.Offset(0, 1).Range("a1").Select
  81. ActiveCell.Value = CCur(cout + garantiebox)
  82. ActiveCell.Offset(0, 1).Range("a1").Select
  83. ActiveCell.Value = Civ
  84. ActiveCell.Offset(0, 1).Range("a1").Select
  85. ActiveCell.Value = UCase(nombox)
  86. ActiveCell.Offset(0, 1).Range("a1").Select
  87. ActiveCell.Value = prenombox
  88. ActiveCell.Offset(0, 1).Range("a1").Select
  89. ActiveCell.Value = adressebox
  90. ActiveCell.Offset(0, 1).Range("a1").Select
  91. ActiveCell.Value = cpbox
  92. ActiveCell.Offset(0, 1).Range("a1").Select
  93. ActiveCell.Value = UCase(villebox)
  94. ActiveCell.Offset(0, 1).Range("a1").Select
  95. ActiveCell.Value = telbox
  96.  
  97. Sheets("voitures").Select
  98. GoTo fin
  99.  
  100. Erreur:
  101. Message = MsgBox("Veuillez saisir tous les champs SVP, merci ", vbOKOnly + vbCritical, "Jerem'Concessionnaire")
  102. fin:
  103.  
  104. End Sub
Lassé par la pub ? Créez un compte