Results 1 to 5 of 5

Thread: Clear Option button from userform
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Apr 2019
    Posts
    226
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Clear Option button from userform

    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 ?

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,177
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    49 Thread(s)

    Default Re: Clear Option button from userform

    Try
    Code:
       For i = 1 To 5
          Controls("OptionButton" & i) = False
       Next i
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    Board Regular
    Join Date
    Apr 2019
    Posts
    226
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Clear Option button from userform

    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 ?

  4. #4
    Board Regular
    Join Date
    Apr 2019
    Posts
    226
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Clear Option button from userform

    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

  5. #5
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,177
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    49 Thread(s)

    Default Re: Clear Option button from userform

    You're welcome & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •