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.
Thanks,
Microsoft ExcelMicrosoft Office
Last Comment
Mike French
8/22/2022 - Mon
Roy Cox
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 = FalseEnd Sub
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. HideComboxonSheet.xlsm ListBox-toComment.xlsm
Mike French
ASKER
Roy,
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.
Roy Cox
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.
Martin Liss
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.
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.