Unique Combobox in Userform

murty473

New Member
Joined
Aug 10, 2011
Messages
8
Hi,

I'm new in here and macros. I would like to create unique comboboxes in my userform. I don't want them to be repeated in combobox.

I have 5 columns and you can see my codes below.

I appreciate for your quick response and help. Please also let me know if you need further information that I'm using.

Code:
Private Sub UserForm_Initialize()
Dim T1 As Range
Dim T2 As Range
Dim T3 As Range
Dim T4 As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")
For Each T1 In ws.Range("ProcessList")
  With Me.Turkcell1
    .AddItem T1.Value
  End With
Next T1
For Each T2 In ws.Range("SubProcessList")
  With Me.Turkcell2
    .AddItem T2.Value
  End With
Next T2
For Each T3 In ws.Range("KPITypeList")
  With Me.Turkcell3
    .AddItem T3.Value
  End With
Next T3
For Each T4 In ws.Range("KPINameList")
  With Me.Turkcell4
    .AddItem T4.Value
  End With
Next T4
Me.Turkcell4.SetFocus
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
This will work:

Code:
Private Sub UserForm_Initialize()
    With Worksheets("LookupLists")
        Me.Turkcell1.List = UniqueEntries(.Range("ProcessList"))
        Me.Turkcell2.List = UniqueEntries(.Range("SubProcessList"))
        Me.Turkcell3.List = UniqueEntries(.Range("KPITypeList"))
        Me.Turkcell4.List = UniqueEntries(.Range("KPINameList"))
    End With
    Me.Turkcell4.SetFocus
End Sub

Function UniqueEntries(rng As Range) As String()
    s = "#"
    For Each r In rng.Cells
        If InStr(s, "#" & r.Text & "#") = 0 Then
            s = s & r.Text & "#"
        End If
    Next
    UniqueEntries = Split(Mid(s, 2, Len(s) - 2), "#")
End Function
 
Upvote 0
Or with slightly different notation:

Code:
Private Sub UserForm_Initialize()
    Me.Turkcell1.List = UniqueEntries([LookupLists!ProcessList])
    Me.Turkcell2.List = UniqueEntries([LookupLists!SubProcessList])
    Me.Turkcell3.List = UniqueEntries([LookupLists!KPITypeList])
    Me.Turkcell4.List = UniqueEntries([LookupLists!KPINameList])
    Me.Turkcell4.SetFocus
End Sub

Function UniqueEntries(rng As Range) As String()
    s = "#"
    For Each r In rng.Cells
        If InStr(s, "#" & r.Text & "#") = 0 Then
            s = s & r.Text & "#"
        End If
    Next
    UniqueEntries = Split(Mid(s, 2, Len(s) - 2), "#")
End Function
 
Upvote 0
Hi Wigi,

Thanks for your reply. It works, do you have any idea about combining this processes. For example when I select an item from Process List, I just want to see the related Sub Process on the combobox.

I really appreciate for your help.

Kind Regards

Or with slightly different notation:

Code:
Private Sub UserForm_Initialize()
    Me.Turkcell1.List = UniqueEntries([LookupLists!ProcessList])
    Me.Turkcell2.List = UniqueEntries([LookupLists!SubProcessList])
    Me.Turkcell3.List = UniqueEntries([LookupLists!KPITypeList])
    Me.Turkcell4.List = UniqueEntries([LookupLists!KPINameList])
    Me.Turkcell4.SetFocus
End Sub
 
Function UniqueEntries(rng As Range) As String()
    s = "#"
    For Each r In rng.Cells
        If InStr(s, "#" & r.Text & "#") = 0 Then
            s = s & r.Text & "#"
        End If
    Next
    UniqueEntries = Split(Mid(s, 2, Len(s) - 2), "#")
End Function
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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