UserForm VBA to validate that 1 of 2 option buttons is selected in a group

  • On a UserForm, I have Frame1 which contains Option Buttons (opt_SalesLine & opt_TechLine) which are used to determine to which worksheet the data will be sent.
    Here's the EnterButton VBA code I have to this point...


    I don't want to make either option default, but I need to make it mandatory that one of these options is selected before the UserForm data can be sent to the appropriate worksheet. Just started with VBA on this side-project, so please, use newbie language :)

  • Re: UserForm VBA to validate that 1 of 2 option buttons is selected in a group


    would the following meet my requirements?

    Code
    If opt_SalesLine.Value = False And _ 
        opt_TechLine.Value = False Then 
            MsgBox "Please select a Call Source", , "Selection Error"
  • Re: UserForm VBA to validate that 1 of 2 option buttons is selected in a group


    it worked, kind of. I got the message, but when I acknowledged it, the form was reset, all fields blank. I need to avoid this obviously. Any assistance greatly appreciated.

  • Re: UserForm VBA to validate that 1 of 2 option buttons is selected in a group


    Quote from bbxl;581954

    it worked, kind of. I got the message, but when I acknowledged it, the form was reset, all fields blank. I need to avoid this obviously. Any assistance greatly appreciated.


    Try this



    If UserForm1.opt_SalesLine.Value = False _
    And UserForm1.opt_TechLine.Value = False Then
    msg = MsgBox("Please select an option.", vbOKOnly + vbInformation, "Select option") Exit SubEnd If

  • Re: UserForm VBA to validate that 1 of 2 option buttons is selected in a group


    edgaryp


    Welcome to the Forum, please read the Forum Rules & use Code Tags when posting code.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!