Hide Combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • grego9
    New Member
    • Feb 2007
    • 63

    Hide Combo box

    I am trying to hide a combo box when the cell value in B57 = FALSE. The ComboBox is called ComboBox1.

    I have tried to do conditional formatting - but can't seem to get that to work for the combobox - so I thought I would try to write a simple macro - i wrote the following ....

    Code:
    Private Sub Range()
      If Range("b57").Value = False Then ComboBox1.Visible = False
    End Sub
    it didn't work - and besides I would rather it hid the combo box automatically when B57 changed rather than having to click a macro button to trigger the box being hidden

    any ideas

    thanks
    Last edited by Frinavale; Jul 21 '09, 08:21 PM. Reason: Please post code in [code] [/code] tags. Added code tags.
  • smartchap
    New Member
    • Dec 2007
    • 236

    #2
    Use following:

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Trim(Cells(57, "B").Value) = "False" Then 
            ComboBox1.Visible = False
        Else
            ComboBox1.Visible = True
        End If
    End Sub

    Comment

    • grego9
      New Member
      • Feb 2007
      • 63

      #3
      ComboBox1 visible

      Thanks for the script - I inserted into my module 1 - but unfortunately it still deosn't work. I don't know if it makes any difference but the Cell B57 is linked to an option button. So if the button is selected the cell B57 value is TRUE and if the button is not selected then the cell value is FALSE. Would this change the script you sent and am I inserting this script in the right place?

      thanks

      Comment

      • grego9
        New Member
        • Feb 2007
        • 63

        #4
        Sorted!

        I did it this way for each of the relevant option button names (the code was on the sheet tab and not in module 1) - apologies for this basic slip up!



        Private Sub canc_Click()
        If OptionButton1 Then
        ComboBox1.Visib le = True

        End If
        End Sub

        Thanks for looking into it and trying to help me

        Comment

        • smartchap
          New Member
          • Dec 2007
          • 236

          #5
          The sub is for any change in the relevant sheet so code must be put in the sheet's code.

          Comment

          Working...