Link to home
Start Free TrialLog in
Avatar of Mike French
Mike FrenchFlag for United States of America

asked on

Make combobox on worksheet disappear after selection with a mouse click

I have a combobox on a worksheet in Excel. I want the combobox to disappear after I make a selection with the mouse. I am using an activex control on a worksheet. it disappears if i select using the enter or tab key. How can I make it disappear after a mouse click. Tried every way i know.

Avatar of Roy Cox
Roy Cox
Flag of United Kingdom of Great Britain and Northern Ireland image

This will do that, make sure the object's name is correct, the code should be in the worksheets module
Private Sub ComboBox1_Click()
ActiveSheet.ComboBox1.Visible = False
End Sub

Open in new window

What are you wanting to do this for?

I've added a workbook to demonstrate and one to show how to use similar code to hide and show a ListBox when cells are selected which might help, this example adds the selection to a cell comment.
Avatar of Mike French



I appreciate the solution but that won't work because the up and down arrow keys fire that event too. I have those keys disabled in the "key up" event code i am running.
How do you want it to work, the up and down arrow keys just activate the click event
Right now if a selection is made using the mouse the dropdown closes and the item selected is in Blue highlight. if I then hit the enter key the combobox becomes invisible. I have tried using the SendKeys command to simulate an enter or tab key but this doesn't work. if you arrow up or down to make a selection and then press the enter or tab key everything works fine. I just don't want to have to hit the enter key after making a selection with the mouse. If I put the code you suggested in the click event, it will fire, close and hide the combobox if someone is trying to use the arrow keys to make a selection because, the click event fires before any of the "Key" events.
Please see this article of mine called The magical floating ActiveX control. In it are two combobox example that you might be able use to get some tips.
Can you attach your workbook?
Avatar of Mike French
Mike French
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial