Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel crash when trying to Autocomplete an ActiveX ComboBox

Tags:

excel

vba

I have an ActiveX Combobox control on a worksheet and this is the _Change event code

Private Sub ComboBox1_Change()
  Me.ComboBox1.ListFillRange = "ItemSearch"
  Me.ComboBox1.DropDown
End Sub

When I use keyboard up/down key to move through the list it automatically quits Excel.

Does anyone know the solution to this problem? I basically want a dynamic ComboBox.

like image 437
Stupid_Intern Avatar asked Feb 10 '17 14:02

Stupid_Intern


1 Answers

You are forcing Combobox's possible values to update when you change the selected option,
that is why it's crashing.

You can try to keep Me.ComboBox1.DropDown in that event.

But the .ListFillRange should be in another event :

  • Workbook_Open
  • Workbook_SheetChange
  • Worksheet_SelectionChange
  • Worksheet_Change

If you're attempting to have a kind of AutoComplete behavior, you can use a built-in property :

  1. Right-click on the Control, click on Properties
  2. In the opened Properties window, find the MatchEntry property
  3. Set it to 0 - fmMatchEntryFirstLetter
like image 71
R3uK Avatar answered Nov 15 '22 18:11

R3uK