Fill a combobox with only one number

santnok

Board Regular
Joined
Jan 10, 2014
Messages
97
Hi

I have a sheet called "Data" and from cell A2 I have many numbers like:

30023
30028
30102
30001

and so on, but in the same list the number can apper many times like

30023
30028
30001
30023
30089
30001

So my question are, how can I fill a combobox, the list of number but if the number has more than one I only want to add it one time.

I have this code on a button

Code:
Private Sub cmdFillCBO_Click()Dim xlSheet As Worksheet
    Dim xlInfo As Worksheet
    Dim i As Integer
    Dim iRow As Integer
    
    Set xlSheet = Worksheets("Data")
    Set xlInfo = Worksheets("Info")
    
    iRow = Worksheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
    
    With xlSheet
        For i = 2 To iRow
        
        
        
            If .Cells(i, 1).Value = "" Then
                Exit For
            End If
            
            cboABO.AddItem (.Cells(i, 1).Value)
        
        Next i
    End With
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Is your Combobox on a userform?
if so try
Code:
    Dim UsdRws As Long
    Dim Dict As Object
    Dim Cl As Range
    Dim Sht As Worksheet
    
    Set Dict = CreateObject("scripting.dictionary")
    Set Sht = Sheets("Data")
    UsdRws = Sht.Range("A" & Rows.Count).End(xlUp).Row
    
    With Dict
        For Each Cl In Sht.Range("A2:A" & UsdRws)
            If Not .exists(Cl.Value) Then .Add Cl.Value, Nothing
        Next Cl
        cdoABO.List = .keys
    End With
In your button click sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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