Consulting

Results 1 to 6 of 6

Thread: OptionButton madness...

  1. #1
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location

    OptionButton madness...

    Hi folks

    I have 2 sets of optionbuttons - each one is being used as a Yes/No answer to a question. Depending on the answer, text is either hidden or revealed. All pretty simple.

    However, if I leave the sheet, having chosen an option, when I return, both optionbuttons are blank - the selected values are not being retained. This is repeated over 3 sheets - each sheet has the same buttons and questions. There is no code running to clear the options. Below is the code for one of the buttons, just for info...
    Private Sub OptionButton5_Click()
    If OptionButton5 Then Range("P15").Font.ColorIndex = 5
    End Sub
    Why won't they retain their selected value?
    Iain - XL2010 on Windows 7

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    When you activate your sheet, check on the colorindex for P15. If it's not the desired color, optionbutton5 wasn't chosen, so that value for optionbutton5 was false. If P15 has the desired color, optionbutton5 = true. (I guess).

  3. #3
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location
    I see what you mean, but why won't the button retain its previously chosen value? That's the bit I don't understand.
    Iain - XL2010 on Windows 7

  4. #4
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Quote Originally Posted by Glaswegian
    I see what you mean, but why won't the button retain its previously chosen value? That's the bit I don't understand.
    Maybe you're resetting them ? Some code on Workbook_SheetChange ? And you're not in design mode ?

  5. #5
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Quote Originally Posted by Glaswegian
    Private Sub OptionButton5_Click()
    If OptionButton5 Then Range("P15").Font.ColorIndex = 5
    End Sub
    Why won't they retain their selected value?
    Why an if ? If you click on the optionbutton, you know it's going to be true.

  6. #6
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location
    That's an 'Oooops' moment...

    There are no Sheet Change Events running, nor any other code that would affect them.

    I decided just to change to checkboxes and all works just fine now.

    Thanks for your help.
    Iain - XL2010 on Windows 7

Posting Permissions

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