Action From Radio Buttons

  • What code do I need to have behind a command button to carry out an action (for example select cell A1 or B1) depending on which one of two radio buttons are selected?
    I have tried:

    Code
    Sub Button23_Click()
    If Opt1 Then
    Range("A1").Select
    End If
    End Sub


    but it does not work


    Thanks


    Suzi

  • Re: Action From Radio Buttons


    Replace the MsgBox here with your Range select.

    Code
    Private Sub CommandButton1_Click()
    Select Case True
        Case OptionButton1 = True
            MsgBox "OptionButton1 was selected."
        Case OptionButton2 = True
            MsgBox "OptionButton2 was selected."
        Case Else
            MsgBox "Neither OptionButton1 nor OptionButton2 was selected."
    End Select
    End Sub
  • Re: Action From Radio Buttons


    you need to check the state of the radiobutton. e.g.

    Code
    x = optionbutton1.value
    if x = true then etc etc

    In formulae, depending on your locale, you might have to replace ; with , or vice versa.

  • Re: Action From Radio Buttons


    Thanks for you replies.
    I still cannot get it to work.
    Dont know if it makes a difference but they are two activeX option buttons in a Forms group box?

  • Re: Action From Radio Buttons


    can you upload the file? stripped to the bare ssentials for size.

    In formulae, depending on your locale, you might have to replace ; with , or vice versa.

  • Re: Action From Radio Buttons


    Hi SuzieQ,


    I left the Group box from the Forms menu but put in option buttons from the Control Toolbox. The Button4 sub is in Module 1 and is common to both Sheets (Could be separated)


    The Opt buttons could also have their own code , no button required as in the second example.


    Cheers,


    dr

Participate now!

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