Problème VBA

Farscape

XLDnaute Junior
bonjour a tous,

Voilà j'ai un probleme avec une formule VBA (voir plus bas)
Dès que je lance cette formule j'ai une erreur bloc if sans end if ou end if sans bloc if.

Pouvez vous m'aider.

Merci

Private Sub CommandButton1_Click()
If ComboBox1 = '' Or TextBox1 = '' Then MsgBox 'Des champs sont vides', vbInformation + vbOKOnly, 'Erreur données !!!'
If OptionButton1 = False And OptionButton2 = False Then MsgBox 'Veuillez indiquez le type d'opération désirée.'
Exit Sub
End If
If OptionButton1 Then
Feuil3.Range('c' & ComboBox1.List(ComboBox1.ListIndex, 1)) = Feuil3.Range('c' & ComboBox1.List(ComboBox1.ListIndex, 1)) + TextBox1
ElseIf OptionButton2 Then
Feuil3.Range('c' & ComboBox1.List(ComboBox1.ListIndex, 1)) = Feuil3.Range('c' & ComboBox1.List(ComboBox1.ListIndex, 1)) - TextBox1
End If
MsgBox 'Mise à jour effectué avec succès'
End Sub
 

Sylvain

XLDnaute Occasionnel
bonjour,

je pense que c'est le deuxième if qui devrait s'écrire comme suit (si on ne va pas à la ligne je crois qu'on ne peut mettre qu'une seule instruction) :

If OptionButton1 = False And OptionButton2 = False Then
  MsgBox 'Veuillez indiquez le type d opération désirée.'
 
Exit Sub
End If
 

Charly2

Nous a quittés en 2006
Repose en paix
Bonsoir Farscape, Sylvain, le forum,

Tu peux modifier ton code comme suit:

Private Sub CommandButton1_Click()
' Ce If est Ok !
If ComboBox1 = '' Or TextBox1 = '' Then MsgBox 'Des champs sont vides', vbInformation + vbOKOnly, 'Erreur données !!!'
' Pour celui-ci, il faut passer à la ligne sinon le End If suivant ne
' sert à rien
If OptionButton1 = False And OptionButton2 = False Then
MsgBox 'Veuillez indiquez le type d'opération désirée.'
Exit Sub
End If
If OptionButton1 Then
Feuil3.Range('c' & ComboBox1.List(ComboBox1.ListIndex, 1)) = Feuil3.Range('c' & ComboBox1.List(ComboBox1.ListIndex, 1)) + TextBox1
ElseIf OptionButton2 Then
Feuil3.Range('c' & ComboBox1.List(ComboBox1.ListIndex, 1)) = Feuil3.Range('c' & ComboBox1.List(ComboBox1.ListIndex, 1)) - TextBox1
End If
MsgBox 'Mise à jour effectué avec succès'
End Sub

Amicalement
Charly
 

Discussions similaires

Réponses
6
Affichages
248
Réponses
11
Affichages
296
Réponses
12
Affichages
448

Statistiques des forums

Discussions
312 241
Messages
2 086 519
Membres
103 241
dernier inscrit
Peyo33