ListBox array

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
 
C

Chip Pearson

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
 

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

Top