PDA

View Full Version : Turn Multiple OptionButtons as False



dzogchen
09-04-2019, 02:52 AM
Hello,

Is there a way to turn multiple OptionButtons as False with a command For, instead of using the following procedure?


Private Sub CommandButton1_Click()OptionButton1.Value = False
OptionButton2.Value = False
OptionButton3.Value = False
OptionButton4.Value = False
OptionButton5.Value = False
OptionButton6.Value = False
OptionButton7.Value = False
OptionButton9.Value = False
OptionButton10.Value = False
OptionButton11.Value = False
OptionButton12.Value = False
OptionButton13.Value = False
OptionButton14.Value = False
OptionButton15.Value = False
...
End Sub

Thank you in advance

Regards

Jan Karel Pieterse
09-04-2019, 04:12 AM
Perhaps like so (assuming these are on a userform):

Private Sub CommandButton1_Click()
Dim Ct as Long
For Ct = 1 to 15
Me.Controls("OptionButton" & Ct).Value = False
Next
End Sub

dzogchen
09-04-2019, 04:52 AM
Perhaps like so (assuming these are on a userform):

Private Sub CommandButton1_Click()
Dim Ct as Long
For Ct = 1 to 15
Me.Controls("OptionButton" & Ct).Value = False
Next
End Sub

Sorry I forgot to mention that the Optionbuttons are in a spreadsheet as an ActiveX control.

Regards

paulked
09-04-2019, 07:11 AM
Force the linked cell for each button to FALSE

paulked
09-04-2019, 07:23 AM
Force the linked cell for each button to FALSE

Kenneth Hobs
09-04-2019, 07:39 AM
Private Sub CommandButton1_Click()
Dim o As OLEObject
For Each o In ActiveSheet.OLEObjects
If TypeName(o.Object) = "OptionButton" Then o.Object = False
Next o
End Sub

dzogchen
09-04-2019, 08:01 AM
Private Sub CommandButton1_Click()
Dim o As OLEObject
For Each o In ActiveSheet.OLEObjects
If TypeName(o.Object) = "OptionButton" Then o.Object = False
Next o
End Sub

Thank you Kenneth Hobs! It works like a charm! This is what I was looking for

Hugs