Populating a listbox from an excel column

J

john.9.williams

I want to populate a list box with data from a column in excel. say
column a sheet 1. the data in the column will have repeated data in
it, but i only want this data added once in the listbox.

e.g column a could be

red
blue
red
yellow
blue
red
red
yellow

but i only want to display in the ist box

red
blue
yellow


I know how to populate a listbox based on a range but cant seem to
work this out

hope someone can help

John
 
G

Greg Glynn

Hi John,

Each time you pick up a new entry, loop through the listbox entries
you already have to see if there is a duplicate.

'Create a For Next Loop to read all the items in the List Box
For Item = 0 to ListBox.ListCount - 1

If ListBox.List(Item) <> {your next candidate} then
(Add the candidate to the list)
Exit for
else
'Duplicate, do nothing
end if

Next item
 
J

john.9.williams

Hi John,

Each time you pick up a new entry, loop through the listbox entries
you already have to see if there is a duplicate.

'Create a For Next Loop to read all the items in the List Box
For Item = 0 to ListBox.ListCount - 1

  If ListBox.List(Item) <> {your next candidate} then
   (Add the candidate to the list)
   Exit for
  else
   'Duplicate, do nothing
  end if

Next item

thanks, just been thinking i think i would need to use a combo box
instead of a list, would the code be much different

john
 

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