Clear Option button from userform

Doflamingo

Board Regular
Joined
Apr 16, 2019
Messages
238
Hi all,

I try to understand why my code to clear option button does not work.

I know how to clear listbox or textbox from userform, code below

Code:
ListBox2.Clear
TextBox1 = ""

But from various optionbuttons in frame, it does not work

Here I have 2 frames, with 4 option button in the 1st frame and 11 optionbutton in the 2nd frame

The code to clean optionbutton below does not work. I have not renamed them, they are called optionbutton1, optionbutton2 etc...until optionbutton15. Same thing for the frame: Frame1, Frame 2

Code:
For i = 1 To 2
      For Each c In Controls("Optionbutton" & Format(i, "00")).Controls
        c.Value = False
      Next c
Next i

Any idea ?:confused:
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try
Code:
   For i = 1 To 5
      Controls("OptionButton" & i) = False
   Next i
 
Upvote 0
Hello @Fluff

Many thanks for your answer. It works for some option button but not for all of them.

For instance if I select optionbutton1 (1st frame)and optionbutton5 (2nd frame) and then activate the commandbutton of your code. Yes that cleans the 2 optionbuttons selected.

But if I select optionbutton1(1st frame) and optionbutton6 (2nd frame) and then activate the commandbutton of your code. It only cleans the optionbutton1 and not the option button 6.

Any ideas ?
 
Upvote 0
Sorry @Fluff

Your code works perfectly. I should have precised that I had 15 option buttons

so here is the code

Code:
For i = 1 To 15
      Controls("OptionButton" & i) = False
   Next i

Many thanks for your help and your time

Kind regards
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top