Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Listbox - Unique Items

Status
Not open for further replies.

nooro

Programmer
Feb 7, 2003
22
0
0
GB
i'm adding items to an excel listbox control, and want only to add those that are unique i.e not in the list already - probably a stupid question, but does anyone have any thoughts?
 
What kind of listbox (on a form, from the control toolbox, or from the forms toolbar)?
Rob
[flowerface]
 
yep, apologies, think before speak is a good idea ^^ It's on a form
 
I think this should do the trick:

Sub AddUniqueItem(cbx as combobox,strItem as string)
dim i as integer
for i=0 to cbx.listcount-1
if ucase(strItem)=ucase(cbx.list(i)) then exit sub
next i
cbx.additem strItem
end sub

Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top