ComboBox does not disappear after selection

claustro

New Member
Joined
Nov 23, 2022
Messages
23
Office Version
  1. 2021
Platform
  1. Windows
Hi all ,
My first message here :)
I am struggling to make the combo box I am using for selecting employees in my timetable disappear after selection.
It disappears only after clicking on another cell.
Is it possible to make it disapear after the click in the dropdown menu?

Another problem is if I click on the line between 2 cells the cursor makes a jump up or down , so you have to carefully select the cell .

I am a total beginner and I copied the vba code from a tutorial so I am unable to understand how I could fix the code
I tried to use the mini sheet feature but if I try to copy my sheet I receive the error: 1004 run-time referred to Set cboTemp = ws.OLEObjects("TempCombo")

this is the code I am using

VBA Code:
'==========================
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
  Cancel As Boolean)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Dim Tgt As Range
Set Tgt = Target.Cells(1, 1)
Set ws = ActiveSheet
On Error GoTo errHandler

If Tgt.Validation.Type = 3 Then
    Cancel = True
End If

Set cboTemp = ws.OLEObjects("TempCombo")
  On Error Resume Next
  With cboTemp
    .ListFillRange = ""
    .LinkedCell = ""
    .Visible = False
  End With
On Error GoTo errHandler

If Tgt.Validation.Type = 3 Then
    Application.EnableEvents = False
    str = Tgt.Validation.Formula1
    str = Right(str, Len(str) - 2)
    With cboTemp
      .Visible = True
      .Left = Tgt.Left
      .Top = Tgt.Top
      .Width = Target.Width + 5
      .Height = Target.Height + 4
      .ListFillRange = ws.Range(str).Address
      .LinkedCell = Tgt.Address
    End With
    cboTemp.Activate
    'open the drop down list automatically
    Me.TempCombo.DropDown
  End If
 
errHandler:
  Application.EnableEvents = True
  Exit Sub

End Sub
'=========================================
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet

Set cboTemp = ws.OLEObjects("TempCombo")
  On Error Resume Next
If cboTemp.Visible = True Then
  With cboTemp
    .Top = 10
    .Left = 10
    .ListFillRange = ""
    .LinkedCell = ""
    .Visible = False
    .Value = ""
  End With
End If

errHandler:
  Application.EnableEvents = True
  Exit Sub

End Sub
'====================================
'Optional code to move to next cell if Tab or Enter are pressed
'from code by Ted Lanham
'***NOTE: if KeyDown causes problems, change to KeyUp
'Table with numbers for other keys such as Right Arrow (39)
'https://msdn.microsoft.com/en-us/library/aa243025%28v=vs.60%29.aspx

Private Sub TempCombo_KeyDown(ByVal _
        KeyCode As MSForms.ReturnInteger, _
        ByVal Shift As Integer)
    Select Case KeyCode
        Case 9 'Tab
            ActiveCell.Offset(0, 1).Activate
        Case 13 'Enter
            ActiveCell.Offset(1, 0).Activate
        Case Else
            'do nothing
    End Select
End Sub
'====================================
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Thank you for answering me.
I show you in this video
I am using it for selecting the emlpoyee from the pool, the normal drop down list can show only 8 items and isn't configrable.
 
Upvote 0
Instead of using a combobox & macro, try using "Search_deList_v2.1", it's a free Excel add-in, it works on Excel 2007 or later.

Its function is to speed up the search in the data validation list. In any cell that has data validation (with type List) pressing ALT+RIGHT will open a User Form with a combobox. You can type multiple keywords (separated by a space) in the combobox to search items on the list.

By using this add-in, you don't need to have the combobox in your workbook, so you can save your files as .xlsx. And it work on any open workbook.

This new version has some additional features, some of them:
Several ways to search, like using AND or OR or LIKE operator , with or without keyword order.
Sort the list by original order or ascending order.
Widen or shorten the combobox width at run time.
Insert multiple entries into the cell.

You can find it here (please check post #81):
 

Attachments

  • search mode default.jpg
    search mode default.jpg
    62.3 KB · Views: 7
Upvote 0
Solution
Your work seems awesome, but I am having problem running it .
I installed the addin correctly checked the confirmation box but maybe I am missing something because I can't activate it.
I tried right mouse click and CTRL , right arrow and CTRL .
The validation list works correctly and ALT right arrow opens the " normal " dropdown list
 
Upvote 0
I tried implementing the code for the double click and it doesn't work, so maybe I am missing soemthing basic here.
1.jpg2.jpg
 
Upvote 0
and ALT right arrow opens the " normal " dropdown list
That's strange.
In VBA window, do you see Search_deList_v2.1.xlam module?
vbe search deList.jpg


Could you upload your workbook (without sensitive data) to a sharing site like dropbox.com or google drive?
And then share the link here.

Edit:
Try saving your workbook, close Excel then reopen Excel & your workbook.
 
Upvote 0
ALT right arrow opens the " normal " dropdown list
If the the add-in doesn't work then pressing Alt+Right arrow shouldn't open anything, so it's strange that it opens the normal data validation.
Are you sure you pressed Alt+Right arrow not Alt+Down arrow?
 
Upvote 0
If the the add-in doesn't work then pressing Alt+Right arrow shouldn't open anything, so it's strange that it opens the normal data validation.
Are you sure you pressed Alt+Right arrow not Alt+Down arrow?
you are right :
- ALT right do nothing
- ALT down open regular drop down list
I don't have the module loaded in VBA window
this is the link , keep in mind I started using excel 15 days ago :)
thank you for your time
 
Upvote 0
Maybe I solved , I went to proprieties of file and the remove block , now it works.
I added the extra code you provided for let the drop down menu open as soon as you double click on a cell and it works flawlessy
What I would like to achieve is :
1) Show all my 25 items without the need of scrolling it
2) I would like that after selection is made the drop down list close itself ( this is the main reason I post my request for help )
Is it possible achieve it?

Thank you
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,730
Members
449,185
Latest member
ekrause77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top