PDA

View Full Version : Solved: Add ListBox item if item exist just once...



SlyGuy77
06-22-2010, 03:29 PM
I'm trying to add items that exist just once to a listbox. I'm not talking about only having unique items in my list, I want to exclude items that exist more than once altogether.

example:

Items from worksheet:
Item A
Item B
Item C
Item A

Desired results in Listbox:
Item B
Item C

Hope you can help.

Thanks.

Bob Phillips
06-22-2010, 04:06 PM
LastRow = Cells(Rows.Count, "A").End(xlUp).Row

For i = 1 To LastRow

If Application.Countif(Cells(i, "A").Value2, Cells(i, "A").Resize(LastRow),0) = 1 Then

Me.ListBox1.AddItem Cells(i, "A").Value2
End If
Next i

p45cal
06-22-2010, 04:09 PM
Private Sub UserForm_Initialize()
For Each cll In Range("A2:A5")
If Application.CountIf(Range("A2:A5"), cll) = 1 Then ListBox1.AddItem cll.Text
Next
End Sub

SlyGuy77
06-22-2010, 04:56 PM
Private Sub UserForm_Initialize()
For Each cll In Range("A2:A5")
If Application.CountIf(Range("A2:A5"), cll) = 1 Then ListBox1.AddItem cll.Text
Next
End Sub


Works like a charm.. thanks for the great help.. :thumb