I have written a code for re-setting all option button on one click but its giving an error, "object doesnt support the property or matter".
Sub Add_New_Record()
Dim i As Integer
For i = 1 To 30
With Sheets("Form")
'-- unlock the worksheet
.Unprotect
.OptionButton(i).Value = False
'-- lock the worksheet
'.Protect
.Activate
.Range("Q12").Select
End With
Next i
End Sub
Can anyone please suggest me how to fix the code and make the value of all option buttons "false" at one.
I know how to do it individually like:
Sub Add_New_Record()
With Sheets("Form")
'-- unlock the worksheet
.Unprotect
.OptionButton1.Value = False
'-- lock the worksheet
'.Protect
.Activate
.Range("Q12").Select
End With
End Sub
but since I have too many buttons, the code will get really long and inefficient.
Thanks for your help and time.
Loop through all the OLEObjects on a particular sheet and if it is an optionbutton then set it to false.
Embedding this snippet in your code:
Read more about OLEObjects here
First, the
With
statement should be before theFor
loop. And it should be.OptionButtons
. Try this one.