Else sans If

Résolu/Fermé
David34300 Messages postés 2 Date d'inscription dimanche 4 mars 2018 Statut Membre Dernière intervention 4 mars 2018 - Modifié le 4 mars 2018 à 17:27
 Gaston - 4 mars 2018 à 23:19
Bonjour à tous
je suis débutant et j' ai créé un formulaire de saisie, mais je ne trouve pas de solution au message d'erreur else sans If
Si vous avez la solution un grand merci
 Private Sub CommandButton3_Click()
'bouton modifier un prospect
Dim modif As Integer
If Not ComboBox1.Value = "" Then
Sheets("Feuil3").Select
modif = ComboBox1.ListIndex + 2
Cells(modif, 1) = ComboBox1.Value
Cells(modif, 2) = TextBox1.Value
Cells(modif, 3) = CheckBox1.Value
If CheckBox1 Then ' équivalent à If CheckBox1.Value = True Then
            Cells(modif, 3).Value = "X"
        Else
            Cells(modif, 3).Value = ""
        End If
Cells(modif, 4) = CheckBox2.Value
If CheckBox2 Then ' équivalent à If CheckBox2.Value = True Then
            Cells(modif, 4).Value = "X"
        Else
            Cells(modif, 4).Value = ""
        End If
 Cells(modif, 5) = CheckBox3.Value
If CheckBox3 Then ' équivalent à If CheckBox3.Value = True Then
            Cells(modif, 5).Value = "X"
        Else
            Cells(modif, 5).Value = ""
MsgBox ("Modification effectuée")
Else <underline>sa coince ici</underline>
MsgBox ("Veuillez sélectionner le modele a modifier")
Exit Sub
End If
Unload UserForm1
UserForm1.Show 0


EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ici : ICI

Merci d'y penser dans tes prochains messages.

1 réponse

ccm81 Messages postés 10854 Date d'inscription lundi 18 octobre 2010 Statut Membre Dernière intervention 26 avril 2024 2 404
Modifié le 4 mars 2018 à 17:35
Bonjour

Au début il manque le End If du If Not ComboBox1 ...
Tes trois dernières lignes devraient être avant la fin de la procédure
Peut être ceci à compléter pour la fin de ta procédure
Private Sub CommandButton3_Click()
'bouton modifier un prospect
Dim modif As Integer
If Not ComboBox1.Value = "" Then
  Sheets("Feuil3").Select
  modif = ComboBox1.ListIndex + 2
  Cells(modif, 1) = ComboBox1.Value
  Cells(modif, 2) = TextBox1.Value
  Cells(modif, 3) = CheckBox1.Value
End If
If CheckBox1 Then ' équivalent à If CheckBox1.Value = True Then
  Cells(modif, 3).Value = "X"
Else
  Cells(modif, 3).Value = ""
End If
Cells(modif, 4) = CheckBox2.Value
If CheckBox2 Then ' équivalent à If CheckBox2.Value = True Then
  Cells(modif, 4).Value = "X"
Else
  Cells(modif, 4).Value = ""
End If
Cells(modif, 5) = CheckBox3.Value
If CheckBox3 Then ' équivalent à If CheckBox3.Value = True Then
  Cells(modif, 5).Value = "X"
Else
  Cells(modif, 5).Value = ""
End If
If à_toi_de_voir Then
  MsgBox ("Modification effectuée")
Else 'sa coince ici
  MsgBox ("Veuillez sélectionner le modele a modifier")
End If
Unload UserForm1
UserForm1.Show 0
End Sub


RQ. Quand u envoies du code, utilise la coloration syntaxique (le symbole flèche bas en haut à droite de la fenetre d'édition)

Cdlmnt
0
David34300 Messages postés 2 Date d'inscription dimanche 4 mars 2018 Statut Membre Dernière intervention 4 mars 2018
4 mars 2018 à 18:01
merci ccm81 pour ton aide, un réponse rapide c top
j'ai trouvé sa marche
encore merci
Private Sub CommandButton3_Click()
'bouton modifier un prospect
Dim modif As Integer
If Not ComboBox1.Value = "" Then
Sheets("Feuil3").Select
modif = ComboBox1.ListIndex + 2
Cells(modif, 1) = ComboBox1.Value
Cells(modif, 2) = TextBox1.Value
Cells(modif, 3) = CheckBox1.Value
If CheckBox1 Then ' équivalent à If CheckBox1.Value = True Then
Cells(modif, 3).Value = "oui"
Else
Cells(modif, 3).Value = "non"
End If
Cells(modif, 4) = CheckBox2.Value
If CheckBox2 Then ' équivalent à If CheckBox1.Value = True Then
Cells(modif, 4).Value = "oui"
Else
Cells(modif, 4).Value = "non"
End If
Cells(modif, 5) = CheckBox3.Value
If CheckBox3 Then ' équivalent à If CheckBox1.Value = True Then
Cells(modif, 5).Value = "oui"
Else
Cells(modif, 5).Value = "non"
End If

MsgBox ("Modification effectuée")
Else
MsgBox ("Veuillez sélectionner le modele a modifier")
Exit Sub
End If
Unload UserForm1
UserForm1.Show 0

End Sub

    
0
yg_be Messages postés 22730 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 477 > David34300 Messages postés 2 Date d'inscription dimanche 4 mars 2018 Statut Membre Dernière intervention 4 mars 2018
4 mars 2018 à 20:28
peux-tu alors marquer le sujet comme résolu, via la roue dentée à droite du titre?
0
Oui, tu as au début un if non fermé par un end if
Il semblerait en fin de programme que le do case soit mieux adapté que le if
0