LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default popluating a list box without having duplicates

I have a list box that i want to populate from an Excel list. The list
would look something like this:

A B
Domain A CompName1
Domain A CompName2
Domain A CompName3
Domain A CompName4
Domain B CompName5
Domain B CompName6
Domain C CompName7

Here is the code I am using:

'begin looking for new list items
Dim RowIndex As Long
Dim StartRow As Long
Dim LastRow As Long
Dim curCell As Range

StartRow = 20

'LastDataRow is a UDF i made that finds the last row with an
entry in it.
LastRow = LastDataRow("DomainDatabase", 1, StartRow)

For RowIndex = StartRow To LastRow
Set curCell = Worksheets("DomainDatabase").Cells(RowIndex,
1)

'check to see if the list is empty
If Me.lstSeriesName.ListCount = 0 Then
'if it is, add the first item to the list
Me.lstSeriesName.AddItem curCell.Value
Else
'If the list isn't empty, find out if the value
' in the cell is already in the listbox
Dim index As Integer
Dim EntryCount As Integer

EntryCount = Me.lstSeriesName.ListCount

For index = 0 To EntryCount
Me.lstSeriesName.ListIndex = index
If Not curCell.Value = Me.lstSeriesName.Value Then
Me.lstSeriesName.AddItem curCell.Value
EntryCount = EntryCount + 1
End If
Next index
End If
Next RowIndex

The problem I have is basically the first domain set will resolve
properly, while the second and subsequent domains will have multiple
listings. The problem appears to be in the following area:

For index = 0 To EntryCount
Me.lstSeriesName.ListIndex = index
If Not curCell.Value = Me.lstSeriesName.Value Then
Me.lstSeriesName.AddItem curCell.Value
EntryCount = EntryCount + 1
End If
Next index

Any help here would be great, I am fairly new to loops much less nested
loops.

Thanks

 
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
List Duplicates Francis Excel Worksheet Functions 4 March 26th 09 06:23 PM
Duplicates in a list jlojones821 Excel Discussion (Misc queries) 1 November 3rd 08 06:56 PM
Condensing a list with duplicates to a list with non-duplicates Nuclear Excel Worksheet Functions 2 July 29th 08 08:03 PM
Array Formulas - Unique List from List with Duplicates Johnny Meredith Excel Discussion (Misc queries) 7 October 27th 06 09:26 PM
How to remove duplicates from a list and copy new list to new colu Chance Excel Worksheet Functions 2 April 23rd 05 05:21 AM


All times are GMT +1. The time now is 06:55 AM.

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

About Us

"It's about Microsoft Excel"