Cocher CheckboxS grace a optionbox

  • Initiateur de la discussion Initiateur de la discussion sim
  • Date de début Date de début

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 !

sim

XLDnaute Occasionnel
Bonjour a tous et a toutes!

Bon vous allez dire FACILE! Mais malheureusement j'arrive pas a trouver la reponse a cette question.

Je voudrais savoir comment programmer ceci:

Dans une Userform

SI optionbox cochee alors coche les checkbox designees:

Le plus proche que j'ai trouve est
Code:
Private Sub OptionButton1_Click()
    If OptionButton1.Tag = True Then
       CheckBox1.Tag = True
       CheckBox2.Tag = True
       CheckBox3.Tag = True
       CheckBox4.Tag = True
       CheckBox5.Tag = True
       CheckBox6.Tag = True
    End If
End Sub

Bon deja ca fonctionne pas!!😛 et en plus je suis sur qu'il y a une solution, plus elegante??🙄

Malheureusement je pense pas, qu'on puisse faire une boucle car dans la meme user form il y a 3 autres option box qui cocheront d'autres check box....

Merci bcp d'avance!!!😀

Sim
 
Re : Cocher CheckboxS grace a optionbox

Re,

essaye avec la propriété "value" plutôt que la propriété "tag" :
Code:
    If OptionButton1.Value = True Then
       CheckBox1.Value = True
       CheckBox2.Value = True
       CheckBox3.Value = True
       CheckBox4.Value = True
       CheckBox5.Value = True
       CheckBox6.Value = True
    End If

bon après midi
@+
 
Re : Cocher CheckboxS grace a optionbox

Re,

Comme toujours NIKEL!!!!

Il y a 187 (et non 188) checkbox en tout pour 4 optionbox......crois tu que je devrai programmer de cete facon pour tout?

Cordialement.

Sim

Edit: du genre Si option Box cochee alors coche de checkbox 1 a checkbox 35...par exemple??
 
Re : Cocher CheckboxS grace a optionbox

Re,

tu peux faire des boucles, comme ceci :

Code:
Dim i As Byte
If OptionButton1.Value = True Then
    For i = 7 To 14
        Me.Controls("CheckBox" & i).Value = True
    Next i
End If

tu adaptes les valeurs de départ et de fin (7 et 14 dans l'exemple) ... maintenant gérer 187 checkbox me parait un peu lourd... mais bon, ce n'est qu'un avis...
 
Re : Cocher CheckboxS grace a optionbox

Bonjour SOune26, Pierrot,

Voila l'option pour laquelle j'ai opte, et qui apparament n'est pas trop lourde puisque je n'ai pas l'impression que la macro travail a l'ecran donc tout est bon.

Je vous met le code, et le fichier joint pour que vous voyez le resultat.

Code:
Private Sub CheckBox188_Click()
Dim i As Byte
If CheckBox188.Value = True Then
    For i = 1 To 35
        Me.Controls("CheckBox" & i).Value = True
    Next i
End If
If CheckBox188.Value = False Then
    For i = 1 To 35
        Me.Controls("CheckBox" & i).Value = False
    Next i
End If
End Sub
Private Sub CheckBox189_Click()
Dim i As Byte
If CheckBox189.Value = True Then
    For i = 36 To 106
        Me.Controls("CheckBox" & i).Value = True
    Next i
End If
If CheckBox189.Value = False Then
    For i = 36 To 106
        Me.Controls("CheckBox" & i).Value = False
    Next i
End If
End Sub
Private Sub CheckBox190_Click()
Dim i As Byte
If CheckBox190.Value = True Then
    For i = 107 To 149
        Me.Controls("CheckBox" & i).Value = True
    Next i
End If
If CheckBox190.Value = False Then
    For i = 107 To 149
        Me.Controls("CheckBox" & i).Value = False
    Next i
End If
End Sub
Private Sub CheckBox191_Click()
Dim i As Byte
If CheckBox191.Value = True Then
    For i = 150 To 187
        Me.Controls("CheckBox" & i).Value = True
    Next i
End If
If CheckBox191.Value = False Then
    For i = 150 To 187
        Me.Controls("CheckBox" & i).Value = False
    Next i
End If
End Sub

Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub CommandButton2_Click()
Dim i As Byte
For i = 1 To 191
        Me.Controls("CheckBox" & i).Value = False
    Next i
End Sub


Comme vous pouvez le constater j'ai change mes optionbox en checkbox car cela ne me permettai pas de cocher deux regions a la fois.

Maintenant je vais ouvrir un autre post, parce que je doit relier le dernier bouton Print, a l'impression des feuille current market, mais ceci est un autre sujet....🙄

Voila! Et merci bcp pour votre aide!!!!

COrdialement

Sim
 

Pièces jointes

- 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
58
Affichages
6 K
Réponses
9
Affichages
997
H
Réponses
19
Affichages
6 K
Réponses
17
Affichages
7 K
G
Retour