Show/Hide ActiveX Option Button

Posted on 2011-05-03
Last Modified: 2012-05-11
Based on the value in a given cell (B11), I'm hoping to show/hide option button 1 and 2.  Is this possible and/or is my code wrong?  Nothing is happening when you change the value in B11.


If Sheets("Master Variables").Range("B11").Value = True Then
    Sheets("Program Set-Up").OptionButton1.Visible = True
    Sheets("Program Set-Up").OptionButton2.Visible = True
End If

If Sheets("Master Variables").Range("B11").Value = False Then
    Sheets("Program Set-Up").OptionButton1.Visible = False
    Sheets("Program Set-Up").OptionButton2.Visible = False
End If
Question by:Golfer219
    LVL 81

    Expert Comment

    by:zorvek (Kevin Jones)
    Have used the debugger and stepped through the code? Is the above code in the Change event handler?

    LVL 81

    Expert Comment

    by:zorvek (Kevin Jones)
    Add this code to the worksheet code module and all will be good:

    Private Sub Worksheet_Change(ByVal Target As Range)

        If Not Intersect(Target, [B11]) Is Nothing Then
            Select Case [B11]
                Case True:
                    OptionButton1.Visible = True
                    OptionButton2.Visible = True
                Case False:
                    OptionButton1.Visible = False
                    OptionButton2.Visible = False
                Case Else:
                    MsgBox "Cell B11 must be TRUE or FALSE."
            End Select
        End If

    End Sub


    Author Comment

    Private Sub CheckBox1_Click()
    LVL 81

    Accepted Solution

    Is the value in B11 TRUE or FALSE? Is the format of the cell NOT Text?

    See attached.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
    I've recently been in need of an Excel macro that could add a letter before the text on multiple cells in an Excel document. My English is as it is, so I will try explain what it does diffrently. If you have an excel document with 2000 rows an…
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
    This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now