Table content to ComboBox

Roschel

New Member
Joined
Apr 24, 2019
Messages
1
Hi,

I have a table with many names in the first column, including repeated names.
I would like to create a combobox and additens with the names of this column, excluding the repeated ones.

Just like the image below:

search
e0a20d2d-48a6-4079-846b-911cbea92850.jpg


Is there a method in vba with listobjects (Table) to do that?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
The code below correctly populates with
Canada
England
France
Spain
Portugal
Germany
Italy

Excel 2016 (Windows) 32 bit
A
B
C
1
Country
2
Canada
3
England
4
France
5
Canada
6
England
7
France
8
Canada
9
England
10
France
11
Canada
12
England
13
France
14
Spain
15
Portugal
16
Germany
17
Italy
18
Sheet: Sheet X


ComboBox1 on " Sheet X" is populated with unique items from table column 1 (NOT column A)
(to refer to table by name : Sheets("Sheet X").ListObjects("CountryList").ListColumns(1).DataBodyRange )

Code:
Private Sub ComboBox1_GotFocus()
    Dim Rng As Range: Set Rng = Sheets("Sheet X").ListObjects(1).ListColumns([COLOR=#ff0000]1[/COLOR]).DataBodyRange
    Call PopulateCombo(ComboBox1, Rng)
End Sub

Sub PopulateCombo(combo As Object, aRange As Range)
    Dim Uneek As New Collection, Cel As Range, T As String
    combo.Clear
    For Each Cel In aRange
        T = Cel.Text
        On Error Resume Next
        If T <> "" Then Uneek.Add T, T
        If Not Err.Number > 0 Then combo.AddItem T
        On Error GoTo 0
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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