![]() |
RemoveItem resetting Value in ComboBox
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? |
RemoveItem resetting Value in ComboBox
pseudo code to give you the concept.
v = Combobox1.Value ' populate the list combobox1.Value = v -- Regards, Tom Ogilvy "Drummer361" wrote: 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? |
RemoveItem resetting Value in ComboBox
Yes!!! Thanks Tom!
Tom Ogilvy wrote: pseudo code to give you the concept. v = Combobox1.Value ' populate the list combobox1.Value = v -- Regards, Tom Ogilvy "Drummer361" wrote: 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? |
All times are GMT +1. The time now is 05:38 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com