Help with combo box

D

David

Hi

I am running a macro that looks at column "a" and populates the cells value
in a combo box using additem.

My problem is that if there are duplicates or blank cells i dont want them
populated in the combo box.

Pleae help

Thanx
 
T

Tod

Try this:

Try this:

'Assuming your value to add to the combo is in cell A1
Sub Sample()
'If Cell A1 is empty, forget it.
If Len(ActiveSheet.Range("A1").Value) = 0 Then Exit Sub
For Each Item In ComboBox1.List
'If the value already exists, forget it....
If trim(ActiveSheet.Range("A1").Value) = trim
(Item) Then
i = 1
Exit For
End If
Next Item
If i = 1 Then
Exit Sub
Else
'....otherwise add it
ComboBox1.AddItem (ActiveSheet.Range("A1").Value)
End If
End Sub
 
Top