Only unique values to a combobox from multiple columns, vba

einheri

New Member
Joined
Aug 15, 2019
Messages
6
Is there a way to collect unique values from several columns (eg E4 to H1500) and put those values into a userform Combobox with no duplicates.

like: E4 F4 G4 H4
row1 Byan PDIV RSI2

Row2 E5 F5 G5 H5
RSI Byan T8 RS

and so on ......

Hope you understand
Thanks
Einheri
[TABLE="width: 237"]
<colgroup><col span="3"><col></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try this:

Code:
Private Sub UserForm_Initialize()
Dim i As Long
Dim va
Dim d As Object

Set d = CreateObject("scripting.dictionary")
va = Sheets("Sheet1").Range("E4:H500")
For i = 1 To UBound(va, 1)
d(va(i, 1)) = Empty
Next
       
       ComboBox1.List = d.keys
End Sub

EDIT: Wait, do you mean you have multi column combobox? If yes then we need different code.
 
Last edited:
Upvote 0
Einheri

From the example data you posted what values would end up in the combobox?
 
Upvote 0
Thanks for the replay.
No I do only have 1 combobox and from this I want to see unique values from E4:H500 even if the same value shows in different cells
so if the value "Byan" shows up in eg. E7 and in G18 or in H400 I only want one value to be visible in the combobox.
Thanks
 
Upvote 0
Thanks for the replay.
No I do only have 1 combobox and from this I want to see unique values from E4:H500 even if the same value shows in different cells
so if the value "Byan" shows up in eg. E7 and in G18 or in H400 I only want one value to be visible in the combobox.
Thanks

OK, then please try the code in post #2 .
 
Upvote 0
Akuini. Tried your solution but it not work Only picked values from the first column and skipped the others.
 
Upvote 0
Akuini. Tried your solution but it not work Only picked values from the first column and skipped the others.
Ah, you're right, my mistake.
Try this one:

Code:
Private Sub UserForm_Initialize()
Dim i As Long
Dim va, x
Dim d As Object

Set d = CreateObject("scripting.dictionary")
va = Sheets("Sheet1").Range("E4:H500")
For Each x In va
d(x) = Empty
Next
       
       ComboBox1.List = d.keys
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top