Combo Box

RhinoNeil

Board Regular
Joined
Dec 16, 2010
Messages
54
I have a form that populates a combo box using a series of prior selections using .additem. The number of items in the list is variable.

I then need to check the combo box contains a mandatory item and if it is not in the list, add it (but not duplicating it if it already exists).

E.g. users can select any numbers between 1 and 10 and they are added to the combo box but the list must always contain a 1 (but I can only do this check after the list has been created).

Can anybody tell me how to check if an entry is in a combo box list?

Thx
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Loop through the combo box's List items:
Code:
    Dim i As Integer
    
    With Me.ComboBox1
        For i = 0 To .ListCount - 1
            If .List(i, 0) = "1" Then Exit For
        Next
        If i = .ListCount Then .AddItem "1", 0
    End With
 
Upvote 0
When you are adding an item just check if it's one.
Code:
... code to add item
' check if last item added was a 1
OneAdded = (Combobox1.List(Combobox1.ListCount-1) = 1)
Once you've added all the other items add the 1 if it's needed:
Code:
If Not OneAdded Then
  Combobox1.AddItem 1
End If
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,673
Members
452,937
Latest member
Bhg1984

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