Hi There,
I have been populating my combobox using this method, is there a faster way of asking the combobox if an element is duplicate? and if it is not to add it in. I know in VB.Net there is a lstbox.items.contains("BAH") as boolean, but is there a similar method in VBA?
Cheers
Ken
Code:Private Sub UserForm_Initialize() 'We need to load up the combo box with the class of chemical Dim i As Integer Dim j As Integer Dim str As String Dim Unique As Boolean Unique = True Me.cboChemical.Clear 'We need to add the option of all items Me.cboChemical.AddItem ("List All") For i = 9 To 88 str = Sheets("Solvent").Cells(i, 1) If str = "" Then 'Do nothing Else 'Probably a more elegant way of doing this Unique = True For j = 0 To Me.cboChemical.ListCount - 1 If str = Me.cboChemical.List(j) Then 'it already exists on the list, exit Unique = False End If Next If Unique = True Then Me.cboChemical.AddItem (str) End If End If Next End Sub





Reply With Quote