Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
populate list box
I am trying to populate a listbox with code by looping through a range of
cells and adding each value, but I don't want the code to additems that have already been added to the list. Any clue on the code to do this? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
populate list box
Take a look at Collection in Help.
This will not permit duplicates. Then populate the listbox with the values in the Collection .....ergo, no duplicates. Regards. "xlcharlie" wrote in message ... I am trying to populate a listbox with code by looping through a range of cells and adding each value, but I don't want the code to additems that have already been added to the list. Any clue on the code to do this? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
populate list box
Try code like the following:
Dim Rng As Range Dim Ndx As Integer Dim Found As Boolean For Each Rng In Range("A1:A10") ' change as necessary Found = False With UserForm1.ListBox1 ' change as necessary For Ndx = 0 To .ListCount - 1 If .List(Ndx) = Rng.Text Then Found = True Exit For End If Next Ndx If Found = False Then .AddItem Rng.Text End If End With Next Rng -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "xlcharlie" wrote in message ... I am trying to populate a listbox with code by looping through a range of cells and adding each value, but I don't want the code to additems that have already been added to the list. Any clue on the code to do this? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Need to auto-populate a list. | Excel Discussion (Misc queries) | |||
How to populate part of a list | Excel Discussion (Misc queries) | |||
Populate List Box | Excel Worksheet Functions | |||
Populate Drop Down List | Excel Worksheet Functions | |||
How do I populate this list | Excel Programming |