Avatar of Mike French
Mike French
Flag 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.

Thanks,
Microsoft ExcelMicrosoft Office

Avatar of undefined
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 = 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.
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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Mike French

ASKER
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.
Roy Cox

Can you attach your workbook?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Mike French

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.