Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default adding into combo box and removing duplicates

i have a list in my spreadsheet which needs to be added to my combo box
list. The problem is that there are repeated number of these values. This is
the code I have written but it does not work as i need it to. Not all the
values have been added into the list. Also for every letter i type in the
combo box this function is called making it slow. If some1 could correct it,
it would be great. Thanks!

Private Sub ComboBox1_Change()
Dim i As Integer
Dim j As Integer
Dim count As Integer
Dim entry As String
Dim check As String

Range("C8",Range("C8").End(xlDown)).Select
count = Selection.Rows.count

Worksheets("Portfolio").Range("DR11")=count
For i = 8 To count
entry = Cells(i, 3).Value
ComboBox1.AddItem (entry)
Next i

For i = 8 To count
entry = Cells(i, 3).Value
For j = i + 1 To count
check = Cells(j, 3).Value
If entry = check Then
ComboBox1.RemoveItem (j)
End If
Next j
Next i
End Sub


It would be great too if some1 cud show me how to sort the list.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default adding into combo box and removing duplicates

See John Walkenbach's article. He uses a listbox, but it is the same for a
combobox.

http://j-walk.com/ss/excel/tips/tip47.htm

However, I wouldn't use the change event. Perhaps the dropdown event. Or if
the data is static, the worksheet activate event.

--
Regards,
Tom Ogilvy


"Abhay Sanan" wrote in message
...
i have a list in my spreadsheet which needs to be added to my combo box
list. The problem is that there are repeated number of these values. This

is
the code I have written but it does not work as i need it to. Not all the
values have been added into the list. Also for every letter i type in the
combo box this function is called making it slow. If some1 could correct

it,
it would be great. Thanks!

Private Sub ComboBox1_Change()
Dim i As Integer
Dim j As Integer
Dim count As Integer
Dim entry As String
Dim check As String

Range("C8",Range("C8").End(xlDown)).Select
count = Selection.Rows.count

Worksheets("Portfolio").Range("DR11")=count
For i = 8 To count
entry = Cells(i, 3).Value
ComboBox1.AddItem (entry)
Next i

For i = 8 To count
entry = Cells(i, 3).Value
For j = i + 1 To count
check = Cells(j, 3).Value
If entry = check Then
ComboBox1.RemoveItem (j)
End If
Next j
Next i
End Sub


It would be great too if some1 cud show me how to sort the list.




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
Removing Duplicates Help Scott Excel Discussion (Misc queries) 6 May 5th 09 03:58 AM
Removing Duplicates Danielle Excel Worksheet Functions 5 March 10th 06 07:56 PM
removing duplicates robhargreaves Excel Discussion (Misc queries) 1 July 24th 05 12:35 AM
Removing Duplicates sat Excel Discussion (Misc queries) 5 June 18th 05 11:18 PM
removing duplicates marina madeleine Excel Programming 0 September 15th 04 06:39 PM


All times are GMT +1. The time now is 06:35 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"