View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default Comparing against values in a combobox??

This might help you get going...

Private Sub CommandButton1_Click()
Dim Cell As Range
Dim CellVal As Variant
ComboBox1.Clear
For Each Cell In Range("A1:A5")
CellVal = Cell.Value
If MatchToList(CellVal) = False Then
ComboBox1.AddItem CellVal
End If
Next
End Sub

Function MatchToList(MatchItem As Variant) As Boolean
Dim Counter As Integer
For Counter = 0 To ComboBox1.ListCount - 1
If MatchItem = ComboBox1.List(Counter) Then
MatchToList = True
Exit Function
End If
Next
End Function

--
Jim
"Mark" wrote in message
...
|I have set an initial item to a combo box. I am now trying to go through an
| array to see if the values of the array are already in the combobox. If
the
| value is not part of the combo box, I want it to be added. Otherwise, I
want
| the next array value to be checked.
|
| What is the correct syntax for addressing the combobox values?
|
| ' Establish array range
| For i = 1 To count
| iArray(i) = rng.Cells(i).Value
| Next i
|
| ' Estabish initial member of combobox
| Set box1 = UserForm1.ComboBox1
| box1.Clear
| box1.AddItem iArray(1)
|
| ' Compare values
| For i = 1 To count
| If iArray(i) < item.box1.Value Then
| box1.AddItem iArray(i)
|
| End If
| Next i
|