Problem with searchable combo box

EtienneD

New Member
Joined
Jul 21, 2022
Messages
27
Office Version
  1. 2016
Platform
  1. Windows
Hi everybody. Here is my problem, I am using a combo box for my dropdown list with multiple data validation and the list appears blank and I don't know why. Here is the code I have used:
*note that the data comes from another sheet*
*note that the data list for the dropdown are not placed vertically, they are left to right*

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

If Target.Count > 1 Then GoTo exitHandler

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

On Error GoTo errHandler
If Target.Validation.Type = 3 Then
'if the cell contains a data validation list
Application.EnableEvents = False
'get the data validation formula
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 15
.Height = Target.Height + 5
.ListFillRange = ws.Range(str).Address
.LinkedCell = Target.Address
End With
cboTemp.Activate
'open the drop down list automatically
Me.TempCombo.DropDown
End If

exitHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub
errHandler:
Resume exitHandler

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)
'Key Code Constants

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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If you're interested, here's an example of a searchable drop-down:

OR

Another option:
I created an Excel add-in for searchable data validation (with combobox) , called "Search deList".
Its function is to speed up the search in the data validation list. It works on multiple cells. In any cell that has data validation (with List type) 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.
It works on any cells that have data validation on any workbook, and you don't need VBA for this.
I share this add-in here:
 
Upvote 0
If you're interested, here's an example of a searchable drop-down:

OR

Another option:
I created an Excel add-in for searchable data validation (with combobox) , called "Search deList".
Its function is to speed up the search in the data validation list. It works on multiple cells. In any cell that has data validation (with List type) 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.
It works on any cells that have data validation on any workbook, and you don't need VBA for this.
I share this add-in here:
Thanks for your response. I actually tried downloading your version B (automatic), but the code seem to not work properly.
 
Upvote 0
I actually tried downloading your version B (automatic), but the code seem to not work properly.
1. Are you saying that the sample workbook doesn't work? Could you elaborate?
2. Could you upload your workbook (without sensitive data) to a sharing site like dropbox.com or google drive?
And then share the link here.
 
Upvote 0
1. Are you saying that the sample workbook doesn't work? Could you elaborate?
2. Could you upload your workbook (without sensitive data) to a sharing site like dropbox.com or google drive?
And then share the link here.
Maybe I did something wrong, I will let you judge. Here is the link to the google drive:


The code is for the Sheet 1 (named TÂCHES COURANTES). The data comes from Sheet 3 (named LISTES) and are all dependent drop list so be careful not to change the source. In the VBA developer section there is 2 codes at the bottom that needs to stay the same (Private Sub Worksheet_Change(ByVal Target As Range) AND Sub SelectAll_Click() ). The 2 other ones on top were for the searchable combo box and can be modified.

Thank you so much for helping
 
Upvote 0
Maybe I did something wrong, I will let you judge. Here is the link to the google drive:


The code is for the Sheet 1 (named TÂCHES COURANTES). The data comes from Sheet 3 (named LISTES) and are all dependent drop list so be careful not to change the source. In the VBA developer section there is 2 codes at the bottom that needs to stay the same (Private Sub Worksheet_Change(ByVal Target As Range) AND Sub SelectAll_Click() ). The 2 other ones on top were for the searchable combo box and can be modified.

Thank you so much for helping
I sent the wrong link, here is the good one:
 
Upvote 0
Try this:
  1. I've changed the combobox name to "Combobox1".
  2. The original code won't work because of Indirect function in dependent data-validation.
  3. In the code, I refer to the cells with dependent data validation in col C (DESCRIPTIONS) in this part:
Rich (BB code):
Private Sub ComboBox1_GotFocus()
Dim x
    
    With ComboBox1
        .MatchEntry = fmMatchEntryNone
        .Value = ""
        .Clear
            Set d = CreateObject("scripting.dictionary"): d.CompareMode = vbTextCompare
            
            If Not Intersect(ActiveCell, Range("C5:C13")) Is Nothing Then  '"C5:C13": cells with data validation in col C (DESCRIPTIONS)
                  vList = Evaluate(Replace(ActiveCell.Offset(, -1), " ", "_"))
            Else
                  vList = Evaluate(ActiveCell.Validation.Formula1)
            End If
 
Upvote 0
Solution
Try this:
  1. I've changed the combobox name to "Combobox1".
  2. The original code won't work because of Indirect function in dependent data-validation.
  3. In the code, I refer to the cells with dependent data validation in col C (DESCRIPTIONS) in this part:
Rich (BB code):
Private Sub ComboBox1_GotFocus()
Dim x
   
    With ComboBox1
        .MatchEntry = fmMatchEntryNone
        .Value = ""
        .Clear
            Set d = CreateObject("scripting.dictionary"): d.CompareMode = vbTextCompare
           
            If Not Intersect(ActiveCell, Range("C5:C13")) Is Nothing Then  '"C5:C13": cells with data validation in col C (DESCRIPTIONS)
                  vList = Evaluate(Replace(ActiveCell.Offset(, -1), " ", "_"))
            Else
                  vList = Evaluate(ActiveCell.Validation.Formula1)
            End If
That is awesome thank you. Any way to activate with a single click instead of a double click? If it's an easy writing I can do the switch.
 
Upvote 0
That is awesome thank you. Any way to activate with a single click instead of a double click? If it's an easy writing I can do the switch.
Nevermind, it works perfectly like that! Thank you again
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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