Help with combo box

  • Thread starter Thread starter David
  • Start date Start date
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top