[RESOLU]un parmis 8 ComboBox soit non vide

chaelie2015

XLDnaute Accro
Bonjour Forum
j ai un USF de 8 COMBObOX , je souhaite appliquer ce code
Code:
If ComboBox1.ListIndex = -1 Then
MsgBox "Nom obligatoire", vbExclamation
Exit Sub
End If
si je valide USF et au moins 1 de COMBObOX NON RENSIEGNER Jaurai ce message ci dessus
Salutations
 
Dernière édition:

chaelie2015

XLDnaute Accro
Re : un parmis 8 ComboBox soit non vide

Re
j ai trouvé CE CODE
Code:
If ComboBox1.ListIndex = -1 And ComboBox2.ListIndex = -1 And ComboBox3.ListIndex = -1 And ComboBox4.ListIndex = -1 And ComboBox5.ListIndex = -1 And ComboBox6.ListIndex = -1 And ComboBox7.ListIndex = -1 And ComboBox8.ListIndex = -1 Then
MsgBox "Nom obligatoire", vbExclamation
Exit Sub
End If
mais il est tres lomg
Salutations
 

mapomme

XLDnaute Barbatruc
Supporter XLD
Re : un parmis 8 ComboBox soit non vide

Bonjour chaelie2015,

(...) mais il est très long (...)

En encore plus long :p mais il en fait un tout petit peu plus :rolleyes:
VB:
Private Sub CommandButton1_Click()
Dim i&
For i = 1 To 8
  If Controls("Combobox" & i).ListIndex = -1 Then
    MsgBox "Pas d'élément sélectionné pour la liste n° " & i & " !", vbExclamation
    Controls("Combobox" & i).SetFocus
    Application.SendKeys ("%{DOWN}")
    Exit Sub
  End If
Next i
End Sub
 

Pièces jointes

  • chaelie2015-Tester ComboBox-v.xlsm
    20.9 KB · Affichages: 39

mapomme

XLDnaute Barbatruc
Supporter XLD
Re : un parmis 8 ComboBox soit non vide

re :),

Mille excuses. J'avais encore une fois mal lu et rattaché à un cas déjà rencontré :mad:
Bon, on adapte le cas précédent:
VB:
Private Sub CommandButton1_Click()
Dim i&, s&
For i = 1 To 8: s = s + Controls("Combobox" & i).ListIndex: Next
If s = -8 Then
  MsgBox "Aucune sélection dans aucune liste!", vbExclamation
  Exit Sub
  End If
End Sub
 

Pièces jointes

  • chaelie2015-Tester ComboBox-v2.xlsm
    21.1 KB · Affichages: 31

Statistiques des forums

Discussions
311 733
Messages
2 082 010
Membres
101 866
dernier inscrit
XFPRO