OVH Cloud OVH Cloud

Boucle sur des Checkbox

2 réponses
Avatar
Fredo
Bonjour à tous

J'ai un userform avec 12 checkbox, je souhaite lorsque je clic sur un bouton
récuperer la valeur de "CAPTION" si le checkbox est coché.
j'ai créé une boucle for next mais vba ne reconnait pas le n° du checkbox

code ci dessous

Private Sub CommandButton3_Click()
Application.ScreenUpdating = False
Feuil1.Cells(65536, 4).Select
Selection.End(xlUp).Select
b = ActiveCell.Row + 1
For a = 1 To 12 '12 sont les 12 Checkbox
If UserForm2.CheckBox(a).Value = True Then
Feuil1.Cells(b, 4).Value = UserForm2.CheckBox(a).Caption
b = b + 1
End If
Next
Application.ScreenUpdating = True
End Sub

Merci de votre aide

2 réponses

Avatar
papou
Bonjour
Tu peux t'inspirer de ça pour ta procédure :
Dim ctr As Control, chk As MSForms.CheckBox
For Each ctr In Me.Controls
If TypeOf ctr Is MSForms.CheckBox Then
Set chk = ctr
If chk.Value = True Then MsgBox chk.Caption
End If
Next ctr

Cordialement
Pascal

"Fredo" a écrit dans le message de news:

Bonjour à tous

J'ai un userform avec 12 checkbox, je souhaite lorsque je clic sur un
bouton
récuperer la valeur de "CAPTION" si le checkbox est coché.
j'ai créé une boucle for next mais vba ne reconnait pas le n° du checkbox

code ci dessous

Private Sub CommandButton3_Click()
Application.ScreenUpdating = False
Feuil1.Cells(65536, 4).Select
Selection.End(xlUp).Select
b = ActiveCell.Row + 1
For a = 1 To 12 '12 sont les 12 Checkbox
If UserForm2.CheckBox(a).Value = True Then
Feuil1.Cells(b, 4).Value = UserForm2.CheckBox(a).Caption
b = b + 1
End If
Next
Application.ScreenUpdating = True
End Sub

Merci de votre aide


Avatar
Fredo
Super!!!!!!!!!!!!!!!!!!! merci Papou


Bonjour
Tu peux t'inspirer de ça pour ta procédure :
Dim ctr As Control, chk As MSForms.CheckBox
For Each ctr In Me.Controls
If TypeOf ctr Is MSForms.CheckBox Then
Set chk = ctr
If chk.Value = True Then MsgBox chk.Caption
End If
Next ctr

Cordialement
Pascal

"Fredo" a écrit dans le message de news:

Bonjour à tous

J'ai un userform avec 12 checkbox, je souhaite lorsque je clic sur un
bouton
récuperer la valeur de "CAPTION" si le checkbox est coché.
j'ai créé une boucle for next mais vba ne reconnait pas le n° du checkbox

code ci dessous

Private Sub CommandButton3_Click()
Application.ScreenUpdating = False
Feuil1.Cells(65536, 4).Select
Selection.End(xlUp).Select
b = ActiveCell.Row + 1
For a = 1 To 12 '12 sont les 12 Checkbox
If UserForm2.CheckBox(a).Value = True Then
Feuil1.Cells(b, 4).Value = UserForm2.CheckBox(a).Caption
b = b + 1
End If
Next
Application.ScreenUpdating = True
End Sub

Merci de votre aide