RemoveItem resetting Value in ComboBox

D

Drummer361

I think I'm missing something obvious, but:

I have a comboBox with the list populated with this code in
UserForm_Initialize():

For j = 12 To 23
UserForm1.comboBox1.AddItem Worksheets("Sheet1").Cells(j, 11).Value
Next j


This works fine and does not reset the value of the ComboBox1 when the
UserForm1 loads.

However, I have another UserForm2 that allows the user to enter Custom
Values into the Lists for comboBox1.

The code I use to repopulate the lists in ComboBox1 after the user
inputs new values is this:

If UserForm1.ComboBox1.ListCount > 0 Then

'Removes current list
For a = 11 To 0 Step -1
UserForm1.ComboBox1.RemoveItem a
Next

'Rebuilds new list
For j = 12 To 23
UserForm1.comboBox1.AddItem Worksheets("Sheet1").Cells(j, 11).Value
Next j

Else

'Rebuilds new list
For j = 12 To 23
UserForm1.comboBox1.AddItem Worksheets("Sheet1").Cells(j, 11).Value
Next j

End If

This works fine, except that it resets the value of the ComboBox1. I
want the value to stay the same and just the list options to
repopulate.

Any ideas?
 
T

Tom Ogilvy

pseudo code to give you the concept.

v = Combobox1.Value

' populate the list

combobox1.Value = v
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top