Problème boucle For

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

craig974

XLDnaute Occasionnel
Bonjour à tous

je souhaite changer cette partie de code :

Code:
If ComboBox3.Value = "1" Or ComboBox5.Value = "1" Or ComboBox7.Value = "1" Or ComboBox9.Value = "1" Then
  CheckBox1.Value = True
End If

If ComboBox3.Value = "2" Or ComboBox5.Value = "2" Or ComboBox7.Value = "2" Or ComboBox9.Value = "2" Then
  CheckBox2.Value = True
End If

If ComboBox3.Value = "3" Or ComboBox5.Value = "3" Or ComboBox7.Value = "3" Or ComboBox9.Value = "3" Then
  CheckBox3.Value = True
End If

If ComboBox3.Value = "4" Or ComboBox5.Value = "4" Or ComboBox7.Value = "4" Or ComboBox9.Value = "4" Then
  CheckBox4.Value = True
End If

If ComboBox3.Value = "5" Or ComboBox5.Value = "5" Or ComboBox7.Value = "5" Or ComboBox9.Value = "5" Then
  CheckBox5.Value = True
End If

If ComboBox3.Value = "6" Or ComboBox5.Value = "6" Or ComboBox7.Value = "6" Or ComboBox9.Value = "6" Then
  CheckBox6.Value = True
End If

If ComboBox3.Value = "7" Or ComboBox5.Value = "7" Or ComboBox7.Value = "7" Or ComboBox9.Value = "7" Then
  CheckBox7.Value = True
End If

If ComboBox3.Value = "8" Or ComboBox5.Value = "8" Or ComboBox7.Value = "8" Or ComboBox9.Value = "8" Then
  CheckBox8.Value = True
End If

par celle ci pour reduire le nombre de ligne de code
Code:
For i = 1 To 8
  If ComboBox3.Value = "" & i Or ComboBox5.Value = "" & i Or ComboBox7.Value = "" & i Or ComboBox9.Value = "" & i Then
    Me.Controls("CheckBox" & i).Value = True
  End If
Next i

Le problème c'est que ca ne marche plus, j'ai besoin d'un oeil extérieur pour voir ce qui cloche.

Merci pour toute aide.

@+
 
Re : Problème boucle For

Re,

j'ai trouvé d’où vient le problème c'est en voulant simplifier cette partie :
Code:
If CheckBox1.Value = True And (ComboBox3.Value = "1" Or ComboBox5.Value = "1" Or ComboBox7.Value = "1" Or ComboBox9.Value = "1") Then
  MsgBox "L'adresse 1 est déjà utilisée", vbCritical
  Exit Sub
ElseIf CheckBox2.Value = True And (ComboBox3.Value = "2" Or ComboBox5.Value = "2" Or ComboBox7.Value = "2" Or ComboBox9.Value = "2") Then
  MsgBox "L'adresse 2 est déjà utilisée", vbCritical
  Exit Sub
ElseIf CheckBox3.Value = True And (ComboBox3.Value = "3" Or ComboBox5.Value = "3" Or ComboBox7.Value = "3" Or ComboBox9.Value = "3") Then
  MsgBox "L'adresse 3 est déjà utilisée", vbCritical
  Exit Sub
ElseIf CheckBox4.Value = True And (ComboBox3.Value = "4" Or ComboBox5.Value = "4" Or ComboBox7.Value = "4" Or ComboBox9.Value = "4") Then
  MsgBox "L'adresse 4 est déjà utilisée", vbCritical
  Exit Sub
ElseIf CheckBox5.Value = True And (ComboBox3.Value = "5" Or ComboBox5.Value = "5" Or ComboBox7.Value = "5" Or ComboBox9.Value = "5") Then
  MsgBox "L'adresse 5 est déjà utilisée", vbCritical
  Exit Sub
ElseIf CheckBox6.Value = True And (ComboBox3.Value = "6" Or ComboBox5.Value = "6" Or ComboBox7.Value = "6" Or ComboBox9.Value = "6") Then
  MsgBox "L'adresse 6 est déjà utilisée", vbCritical
  Exit Sub
ElseIf CheckBox7.Value = True And (ComboBox3.Value = "7" Or ComboBox5.Value = "7" Or ComboBox7.Value = "7" Or ComboBox9.Value = "7") Then
  MsgBox "L'adresse 7 est déjà utilisée", vbCritical
  Exit Sub
ElseIf CheckBox8.Value = True And (ComboBox3.Value = "8" Or ComboBox5.Value = "8" Or ComboBox7.Value = "8" Or ComboBox9.Value = "8") Then
  MsgBox "L'adresse 8 est déjà utilisée", vbCritical
  Exit Sub
Else: CommandButton2.Enabled = True
  CommandButton2.Visible = True
End If
que sa bloqué la partie suivante

Donc merci pour les solutions proposées plus haut qui étaient bonnes (est peut etre que ce que je proposais marchait aussi...) Maintenant faut que je trouve comment bien simplifier ce bout de code
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
7
Affichages
188
Réponses
5
Affichages
275
Réponses
10
Affichages
292
Réponses
5
Affichages
242
Réponses
4
Affichages
203
Réponses
8
Affichages
237
  • Question Question
XL 2021 VBA excel
Réponses
4
Affichages
180
Retour