excel - Repopulate a combobox itemlist without affecting what is currently written inside the combobox? -


how can repopulate combobox itemlist without affecting written inside combobox?

i have code looks kind of like:

private sub combobox1_dropbuttonclick()     dim v variant     dim seltext string     seltext = combobox1.seltext      dim integer     = 0 combobox1.listcount - 1         combobox1.removeitem (0)     next      v = call createlist()     = 0 ubound(v)         combobox1.additem v(i)     next v     if seltext <> "" combobox1.text = seltext end sub 

i haven't worked comboboxes before there better methods. code above has several problems

  • it changes selected value of combobox (before attempting restore it)
  • it triggers combobox1_change event
  • there loops think might unnecessary. is possible remove items without looping , adding multiple items without looping. items added created string has comma separated values.

i appreciate

there loops think might unnecessary. is possible remove items without looping , adding multiple items without looping.

combobox1.clear remove items without looping. adding can use .list after create loop add items combobox.

private sub sample()     dim myar(1 5)      = 1 5         myar(i) =     next      combobox1.list = myar end sub 

it triggers combobox1_change event

to prevent combobox1_change event, have use boolean variable this

it changes selected value of combobox (before attempting restore it)

store value in variable , reset combobox value if value part of dropdown list


Comments