ListBox array

  • Thread starter Thread starter Neil
  • Start date Start date
N

Neil

Hi, as part of my sheet upon a given event I add an item
to a list box, but in some cases I can get the same item
added twice. I want to check the listbox forst to see if
a piece of text alreay exists on the list box, how do I
go about this ?

Many thanks in advance
 
Neil,

You have to loop through the contents of the list box's List to determine if
the item already exists. E.g.,

Dim Ndx As Long
Dim Found As Boolean
With Me.ListBox1
For Ndx = 0 To .ListCount - 1
If .List(Ndx) = "whatever" Then
Found = True
Exit For
End If
Next Ndx
If Found = False Then
.AddItem "whatever"
End If
End With


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Back
Top