Connecting Tech Pros Worldwide Forums | Help | Site Map

Hide Combo box

Member
 
Join Date: Feb 2007
Posts: 43
#1: Jul 21 '09
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 ....

Expand|Select|Wrap|Line Numbers
  1. Private Sub Range()
  2.   If Range("b57").Value = False Then ComboBox1.Visible = False
  3. 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

smartchap's Avatar
Familiar Sight
 
Join Date: Dec 2007
Location: Lucknow, India
Posts: 194
#2: Jul 22 '09

re: Hide Combo box


Use following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.  
  3.     If Trim(Cells(57, "B").Value) = "False" Then 
  4.         ComboBox1.Visible = False
  5.     Else
  6.         ComboBox1.Visible = True
  7.     End If
  8. End Sub
  9.  
Member
 
Join Date: Feb 2007
Posts: 43
#3: Jul 23 '09

re: Hide Combo box


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
Member
 
Join Date: Feb 2007
Posts: 43
#4: Jul 23 '09

re: Hide Combo box


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.Visible = True

End If
End Sub

Thanks for looking into it and trying to help me
smartchap's Avatar
Familiar Sight
 
Join Date: Dec 2007
Location: Lucknow, India
Posts: 194
#5: Jul 24 '09

re: Hide Combo box


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


Similar Visual Basic 4 / 5 / 6 bytes