Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to auto-populate a list. Labkhand Excel Discussion (Misc queries) 16 October 29th 08 12:35 PM
How to populate part of a list dj479794 Excel Discussion (Misc queries) 2 July 2nd 07 10:10 AM
Populate List Box John in Surrey Excel Worksheet Functions 0 October 26th 05 11:25 AM
Populate Drop Down List Wuttie Excel Worksheet Functions 1 May 2nd 05 08:21 PM
How do I populate this list HotRod Excel Programming 3 February 7th 05 06:21 PM


All times are GMT +1. The time now is 07:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"