|
-
Oct 2nd, 2009, 02:57 PM
#1
Thread Starter
PowerPoster
adding distinct value in combobox...
Have a userforn in a vba for excel project
In column A (started from A2) have alist of value:
AAAAA
AAAAA
BBBBBB
CCCCC
CCCCC
CCCCC
....
how to fill combobox without dupes from column A?
-
Oct 2nd, 2009, 03:48 PM
#2
Re: adding distinct value in combobox...
The answer lies in your thread which I answered in March 6th 2009 
http://www.vbforums.com/showthread.php?t=560486
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 2nd, 2009, 11:06 PM
#3
Re: adding distinct value in combobox...
If your worksheet has 5000 items in column A, you should NOT add all of them to the combobox then search to remove 4900 duplicate items, ie. Do not add an item if it is already there.
This is one way to do it: (items added to combobox will also be sorted)
Code:
Private Sub UserForm_Initialize()
Dim sItem As String
Dim i As Long
Dim r As Long
'-- use CStr() to prevent cell contains error:
' #N/A will be converted to "Error 2042",
' #DIV/0! will be converted to "Error 2007", ...
With Me.ComboBox1
r = 2
sItem = CStr(Sheet1.Cells(r, 1))
Do While Len(sItem) > 0
For i = 0 To .ListCount - 1
If sItem <= .List(i) Then Exit For
Next
If i >= .ListCount Then
.AddItem sItem
ElseIf sItem < .List(i) Then
.AddItem sItem
'-- if sItem = .List(i) then do not add it
End If
r = r + 1
sItem = CStr(Sheet1.Cells(r, 1))
Loop
End With
End Sub
-
Oct 3rd, 2009, 02:31 AM
#4
Re: adding distinct value in combobox...
Luca what is your data range? Remember time taken to sort data (In your Case) is totally dependent on the number of items that you want to sort and not on the time taken to add items to combobox...
Adding of items whether it is 5 items, 1000 items, 10000 items or 655356 items in your case will take less than 1 second!!!
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 3rd, 2009, 06:35 AM
#5
Banned
Re: adding distinct value in combobox...
 Originally Posted by koolsid
Luca what is your data range? Remember time taken to sort data ( In your Case) is totally dependent on the number of items that you want to sort and not on the time taken to add items to combobox...
Adding of items whether it is 5 items, 1000 items, 10000 items or 655356 items in your case will take less than 1 second!!! 
This is a stup.. advice that I have ever seen!
The time to sort on adding is much less than the time to search to remove duplicate items.
Wake up! The way the Oz guy uses is the best choice.
-
Oct 3rd, 2009, 01:38 PM
#6
Thread Starter
PowerPoster
Re: adding distinct value in combobox...
-
Oct 3rd, 2009, 02:38 PM
#7
Re: adding distinct value in combobox...
 Originally Posted by luca90
Wow!!!!!!!!!!!!
tks to remember me this post!
note:
But wth you are in your mind? A Gigabit of hardisk and a 3 Giga of memeory?    
Glad to be of help
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|